2017-03-21 3 views
1

저는 각도기 및 오이 프레임 워크에 새로운 기능입니다. 나는 각도기 사이트와 여기 https://semaphoreci.com/community/tutorials/getting-started-with-protractor-and-cucumber에서 계단을 따랐다. 나는 구성 파일 오이 프레임 워크 옵션, 기능 파일 및 단계 정의 파일로 구성되어 있습니다. 하지만 내 오이 설정 파일을 실행하면 내 단계 정의를 인식하지 못하고 항상 오류가 발생합니다. 이것에 대한 도움이 필요하십니까? 아래에 제 설정 파일이 있습니다.각도기 설정 파일이 오이 단계 정의를 선택하지 않습니다

Protractor folder structure

이 //cucumber-config.js

exports.config = { 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
    capabilities: { 
     browserName:'chrome' 
    }, 
    framework: 'custom', 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    specs: [ 
    './features/*.feature' 
    ], 
    cucumberOpts: { 
    require: ['./features/step_definitions/*.steps.js'], 
    tags: [], 
    strict: true, 
    format: ["pretty"], 
    dryRun: false, 
    compiler: [] 
    }, 
    onPrepare: function() { 
    browser.manage().window().maximize(); 
    } 
}; 

//testone.feature

#features/test.feature 
Feature: Running Cucumber with Protractor 

    Scenario: Protractor and Cucumber Test 
     Given I go to "https://angularjs.org/" 
     When I add "Be Awesome" in the task field 
     And I click the add button 
     Then I should see my new task in the list 

//testone_steps.js

var chai = require('chai'); 
var chaiAsPromised = require('chai-as-promised'); 

chai.use(chaiAsPromised); 
var expect = chai.expect; 

module.exports = function() { 
    this.Given(/^I go to "([^"]*)"$/, function(site) { 
    browser.get(site); 
    }); 

    this.When(/^I add "([^"]*)" in the task field$/, function(task) { 
    element(by.model('todoList.todoText')).sendKeys(task); 
    }); 

    this.When(/^I click the add button$/, function() { 
    var el = element(by.css('[value="add"]')); 
    el.click(); 
    }); 

    this.Then(/^I should see my new task in the list$/, function(callback) { 
    var todoList = element.all(by.repeater('todo in todoList.todos')); 
    expect(todoList.count()).to.eventually.equal(3); 
    expect(todoList.get(2).getText()).to.eventually.equal('Do not Be Awesome') 
     .and.notify(callback); 
    }); 
}; 

실행에지금 개발에 -, 내가
/opt/protractor_tests 
➔ protractor cucumber.config.js 
(node:3963) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. 
[21:19:17] I/launcher - Running 1 instances of WebDriver 
[21:19:17] I/hosted - Using the selenium server at http://localhost:4444/wd/hub 
Feature: Running Cucumber with Protractor 

    Scenario: Protractor and Cucumber Test 
    ? Given I go to "https://angularjs.org/" 
    ? When I add "Be Awesome" in the task field 
    ? And I click the add button 
    ? Then I should see my new task in the list 

Warnings: 

1) Scenario: Protractor and Cucumber Test - features/testone.feature:4 
    Step: Given I go to "https://angularjs.org/" - features/testone.feature:5 
    Message: 
    Undefined. Implement with the following snippet: 

     Given('I go to {stringInDoubleQuotes}', function (stringInDoubleQuotes, callback) { 
     // Write code here that turns the phrase above into concrete actions 
     callback(null, 'pending'); 
     }); 

2) Scenario: Protractor and Cucumber Test - features/testone.feature:4 
    Step: When I add "Be Awesome" in the task field - features/testone.feature:6 
    Message: 
    Undefined. Implement with the following snippet: 

     When('I add {stringInDoubleQuotes} in the task field', function (stringInDoubleQuotes, callback) { 
     // Write code here that turns the phrase above into concrete actions 
     callback(null, 'pending'); 
     }); 

3) Scenario: Protractor and Cucumber Test - features/testone.feature:4 
    Step: And I click the add button - features/testone.feature:7 
    Message: 
    Undefined. Implement with the following snippet: 

     When('I click the add button', function (callback) { 
     // Write code here that turns the phrase above into concrete actions 
     callback(null, 'pending'); 
     }); 

4) Scenario: Protractor and Cucumber Test - features/testone.feature:4 
    Step: Then I should see my new task in the list - features/testone.feature:8 
    Message: 
    Undefined. Implement with the following snippet: 

     Then('I should see my new task in the list', function (callback) { 
     // Write code here that turns the phrase above into concrete actions 
     callback(null, 'pending'); 
     }); 

1 scenario (1 undefined) 
4 steps (4 undefined) 
0m00.000s 
[21:19:22] I/launcher - 0 instance(s) of WebDriver still running 
[21:19:22] I/launcher - chrome #01 failed 1 test(s) 
[21:19:22] I/launcher - overall: 1 failed spec(s) 
[21:19:22] E/launcher - Process exited with error code 1 

/opt/protractor_tests 
➔ 

그것은 CucumberJS 2.0.0+ 구문을 사용하려고

[15:22:59] I/launcher - Running 1 instances of WebDriver 
[15:22:59] I/hosted - Using the selenium server at http://localhost:4444/wd/hub 
Feature: Running Cucumber with Protractor 

    Scenario: Protractor and Cucumber Test 
    √ Given I go to "https://angularjs.org/" 
    √ When I add "Be Awesome" in the task field 
    √ And I click the add button 
    × Then I should see my new task in the list 

Failures: 

1) Scenario: Protractor and Cucumber Test - features\testone.feature:4 
    Step: Then I should see my new task in the list - features\testone.feature:8 
    Step Definition: features\step_definitions\testone.steps.js:22 
    Message: 
    Error: function timed out after 5000 milliseconds 
     at Timeout.<anonymous> (<local>\ProtractorTests\node_modules\cucumber\lib\user_code_runner.js:91:22) 
     at ontimeout (timers.js:365:14) 
     at tryOnTimeout (timers.js:237:5) 
     at Timer.listOnTimeout (timers.js:207:5) 

1 scenario (1 failed) 
4 steps (1 failed, 3 passed) 
0m05.049s 
[15:23:19] I/launcher - 0 instance(s) of WebDriver still running 
[15:23:19] I/launcher - chrome #01 failed 1 test(s) 
[15:23:19] I/launcher - overall: 1 failed spec(s) 
[15:23:19] E/launcher - Process exited with error code 1 
error Command failed with exit code 1. 

답변

6

실행 오류로 업데이트 ... 아래의 오류가 발생합니다. 아래의 1.3.1에

하나의 다운 그레이드 CucumberJS, 또는 단계 정의에이 작업을 수행 : 거기 CucumberJS 2.0.0+ 구문입니다

var chai = require('chai'), 
    expect = chai.expect, 
    chaiAsPromised = require('chai-as-promised'); 
chai.use(chaiAsPromised); 

var {defineSupportCode} = require('cucumber'); 

defineSupportCode(({Given, When, Then}) => { 
    Given(/^I go to "([^"]*)"$/, function(site) { 
    return browser.get(site); 
    }); 

    When(/^I add "([^"]*)" in the task field$/, function(task) { 
    return element(by.model('todoList.todoText')).sendKeys(task); 
    }); 

    When(/^I click the add button$/, function() { 
    var el = element(by.css('[value="add"]')); 
    return el.click(); 
    }); 

    Then(/^I should see my new task in the list$/, function() { 
    var todoList = element.all(by.repeater('todo in todoList.todos')); 
    expect(todoList.count()).to.eventually.equal(3); 
    return expect(todoList.get(2).getText()).to.eventually.equal('Do not Be Awesome'); 
    }); 
}); 

편집

CucumberJS 2.0.0에서 시간 제한을 설정하는 두 가지 방법입니다.

기본 시간 초과

이 당신이 가지고있는 모든 시나리오에 대한 기본 시간 제한을 설정하는 것입니다 :이 예에서

let scenarioTimeout = 200 * 1000, 
    {defineSupportCode} = require('cucumber'); 

defineSupportCode(({setDefaultTimeout}) => { 
    setDefaultTimeout(scenarioTimeout); 
}); 

, 나는 200 초 시나리오 시간 제한을 설정하고 있습니다. 적절한 것으로 생각하는대로 변경할 수 있습니다.

개별 단계

이 느린 단계에 대한 시간 제한을 설정하는 것입니다

:이 예에서

When(/^I click the add button$/, {timeout: 60 * 1000}, function() { 
    var el = element(by.css('[value="add"]')); 
    return el.click(); 
    }); 

는, 제한 시간을 60 초로 설정되어,이 크게 또는 작게 할 수 있습니다, 무슨 일을하는지에 따라설정 파일에서

+0

사용자는 "When"문에서 webdrivers 약속을 반환해야합니까? – cnishina

+0

개인적으로, 나는 나의 모든 단계 정의 내에서 마지막 문장에 대한 답을 사용합니다. 그래서 나는 당신이해야한다고 말하고 싶습니다. 이것은 실제로 패스가 표시되기 전에 단계가 실행되도록합니다. –

+0

@Kyle Thanks much. 그것은 작동하지만 항상 오류 단계로 마지막 단계를 받고있다 : 오류 : 5000 밀리 초 후에 기능 시간 초과. 전체 오류 메시지로 질문을 업데이트했습니다. 도와주세요. – mmar

0

:

require: ['./features/step_definitions/*.steps.js'], 

그러나 파일은 다음과 같습니다 testone_steps.js, 그것은해야한다 : testone.steps.js

D' 당신이 차이를 볼? 구성 파일에 사용 중이기 때문에 _.으로 변경하십시오. .