量角器配置文件没有选择黄瓜步骤定义 [英] protractor config file is not picking up the cucumber step definitions
问题描述
我是量角器和黄瓜框架的新手.我按照量角器网站和这里的步骤
//黄瓜配置.js
exports.config = {seleniumAddress: 'http://localhost:4444/wd/hub',能力:{浏览器名称:'chrome'},框架:'自定义',frameworkPath: require.resolve('protractor-cucumber-framework'),眼镜: ['./features/*.feature'],黄瓜选择:{要求:['./features/step_definitions/*.steps.js'],标签: [],严格:真实,格式:[漂亮"],干运行:假,编译器:[]},onPrepare: 函数 () {browser.manage().window().maximize();}};
//testone.feature
#features/test.feature特点:用量角器运行黄瓜场景:量角器和黄瓜测试鉴于我去https://angularjs.org/"当我在任务字段中添加Be Awesome"时然后我点击添加按钮然后我应该在列表中看到我的新任务
//testone_steps.js
var chai = require('chai');var chaiAsPromised = require('chai-as-promised');chai.use(chaiAsPromised);变种期望 = chai.expect;module.exports = 函数() {this.Given(/^I go to "([^"]*)"$/, function(site) {browser.get(站点);});this.When(/^我在任务字段中添加"([^"]*)"$/, function(task) {element(by.model('todoList.todoText')).sendKeys(task);});this.When(/^我点击添加按钮$/, function() {var el = element(by.css('[value="add"]'));el.click();});this.Then(/^我应该在列表中看到我的新任务$/, function(callback) {var todoList = element.all(by.repeater('todo in todoList.todos'));期望(todoList.count()).to.eventually.equal(3);expect(todoList.get(2).getText()).to.eventually.equal('不要太棒了').and.notify(回调);});};
在运行 protractor cucumber-conf.js
时,出现以下错误...
/opt/protractor_tests➔ 量角器 cucumber.config.js(node:3963) DeprecationWarning: os.tmpDir() 已弃用.请改用 os.tmpdir().[21:19:17] I/launcher - 运行 1 个 WebDriver 实例[21:19:17] I/hosted - 在 http://localhost:4444/wd/hub 使用 selenium 服务器特点:用量角器运行黄瓜场景:量角器和黄瓜测试?鉴于我去https://angularjs.org/"?当我在任务字段中添加Be Awesome"时?然后我点击添加按钮?然后我应该在列表中看到我的新任务警告:1)场景:量角器和黄瓜测试 - features/testone.feature:4步骤:鉴于我去https://angularjs.org/" - features/testone.feature:5信息:不明确的.使用以下代码段实现:Given('我去 {stringInDoubleQuotes}', function (stringInDoubleQuotes, callback) {//在这里编写代码,将上面的短语转化为具体的动作回调(空,待定");});2)场景:量角器和黄瓜测试 - features/testone.feature:4步骤:当我在任务字段中添加Be Awesome"时 - features/testone.feature:6信息:不明确的.使用以下代码段实现:When('我在任务字段中添加 {stringInDoubleQuotes}', function (stringInDoubleQuotes, callback) {//在这里编写代码,将上面的短语转化为具体的动作回调(空,待定");});3)场景:量角器和黄瓜测试 - features/testone.feature:4步骤:然后我单击添加按钮 - features/testone.feature:7信息:不明确的.使用以下代码段实现:When('我点击添加按钮', function (callback) {//在这里编写代码,将上面的短语转化为具体的动作回调(空,待定");});4)场景:量角器和黄瓜测试 - features/testone.feature:4步骤:然后我应该在列表中看到我的新任务 - features/testone.feature:8信息:不明确的.使用以下代码段实现:Then('我应该在列表中看到我的新任务', function (callback) {//在这里编写代码,将上面的短语转化为具体的动作回调(空,待定");});1 个场景(1 个未定义)4 个步骤(4 个未定义)0m00.000s[21:19:22] I/launcher - 0 个 WebDriver 实例仍在运行[21:19:22] I/launcher - chrome #01 失败 1 次测试[21:19:22] I/launcher - 总体:1 个失败的规范[21:19:22] E/launcher - 进程退出,错误代码为 1/opt/protractor_tests➔
更新时出现执行错误
[15:22:59] I/launcher - 运行 1 个 WebDriver 实例[15:22:59] I/hosted - 在 http://localhost:4444/wd/hub 使用 selenium 服务器特点:用量角器运行黄瓜场景:量角器和黄瓜测试√ 鉴于我去https://angularjs.org/"√ 当我在任务栏添加Be Awesome"时√ 我点击添加按钮× 然后我应该在列表中看到我的新任务失败:1)场景:量角器和黄瓜测试 - features estone.feature:4步骤:然后我应该在列表中看到我的新任务 - features estone.feature:8步骤定义:featuresstep_definitions estone.steps.js:22信息:错误:函数在 5000 毫秒后超时在超时.<匿名>(<local>ProtractorTests
ode_modulescucumberlibuser_code_runner.js:91:22)在 ontimeout (timers.js:365:14)在 tryOnTimeout (timers.js:237:5)在 Timer.listOnTimeout (timers.js:207:5)1 个场景(1 个失败)4 个步骤(1 个失败,3 个通过)0m05.049s[15:23:19] I/launcher - 0 个 WebDriver 实例仍在运行[15:23:19] I/launcher - chrome #01 失败 1 次测试[15:23:19] I/launcher - 总体:1 个失败的规范[15:23:19] E/launcher - 进程退出,错误代码为 1错误命令失败,退出代码为 1.
它正在尝试使用 CucumberJS 2.0.0+ 语法 - 目前正在开发中.
将 CucumberJS 降级到 1.3.1 或更低版本,或者对您的步骤定义执行此操作:
var chai = require('chai'),期望 = chai.expect,chaiAsPromised = require('chai-as-promised');chai.use(chaiAsPromised);var {defineSupportCode} = 要求('黄瓜');defineSupportCode(({Given, When, Then}) => {Given(/^I go to "([^"]*)"$/, function(site) {返回 browser.get(site);});当(/^我在任务字段中添加"([^"]*)"$/, function(task) {return element(by.model('todoList.todoText')).sendKeys(task);});当(/^我点击添加按钮$/, function() {var el = element(by.css('[value="add"]'));返回 el.click();});然后(/^我应该在列表中看到我的新任务$/, function() {var todoList = element.all(by.repeater('todo in todoList.todos'));期望(todoList.count()).to.eventually.equal(3);return expect(todoList.get(2).getText()).to.eventually.equal('不要太棒了');});});
CucumberJS 2.0.0+ 语法是什么
编辑
在 CucumberJS 2.0.0 中有两种设置超时的方法
默认超时
这是为您拥有的所有场景设置默认超时:
让scenarioTimeout = 200 * 1000,{defineSupportCode} = 要求('黄瓜');defineSupportCode(({setDefaultTimeout}) => {设置默认超时(场景超时);});
在本例中,我将场景超时设置为 200 秒.您可以将其更改为您认为合适的任何内容.
各个步骤
这是为慢步设置超时:
When(/^我点击添加按钮$/, {timeout: 60 * 1000}, function() {var el = element(by.css('[value="add"]'));返回 el.click();});
在此示例中,超时设置为 60 秒,您可能需要更大或更小,具体取决于步骤正在执行的操作.
i am new to protractor and cucumber framework. i followed the steps from protractor site and here https://semaphoreci.com/community/tutorials/getting-started-with-protractor-and-cucumber. i have a config file configured with cucumber framework options, feature file and step definition file. But when i run my cucumber-config file it does not recognize my step definitions and always throw an error. any help on this? below are my setup files.
//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);
});
};
when in run protractor cucumber-conf.js
, i get the below error...
/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
➔
Updated With Execution error
[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 estone.feature:4
Step: Then I should see my new task in the list - features estone.feature:8
Step Definition: featuresstep_definitions estone.steps.js:22
Message:
Error: function timed out after 5000 milliseconds
at Timeout.<anonymous> (<local>ProtractorTests
ode_modulescucumberlibuser_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.
It's trying to use CucumberJS 2.0.0+ syntax - which is in development at the moment.
Either downgrade CucumberJS to 1.3.1 or below, or do this to your step definitions:
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');
});
});
Which is the CucumberJS 2.0.0+ syntax
Edit
There are two ways of setting timeouts in CucumberJS 2.0.0
Default timeout
This is to set the default timeout for all of the scenarios that you have:
let scenarioTimeout = 200 * 1000,
{defineSupportCode} = require('cucumber');
defineSupportCode(({setDefaultTimeout}) => {
setDefaultTimeout(scenarioTimeout);
});
In this example, I am setting the scenario timeout to 200 seconds. You can change this to whatever you feel is appropriate.
Individual Steps
This is to set the timeout for a slow step:
When(/^I click the add button$/, {timeout: 60 * 1000}, function() {
var el = element(by.css('[value="add"]'));
return el.click();
});
In this example, the timeout is set to 60 seconds, you may want this larger or smaller, depending on what the step is doing.
这篇关于量角器配置文件没有选择黄瓜步骤定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!