量角器配置文件未获取黄瓜步骤定义 [英] protractor config file is not picking up the cucumber step definitions
问题描述
< img src = https://i.stack.imgur.com/dsgdQ.png alt =量角器文件夹结构>
// cucumber -config.js
exports.config = {
seleniumAddress:'http:// localhost:4444 / wd /中心,
功能:{
browserName:'chrome'
},
框架:'custom',
框架路径:require.resolve('protractor-cucumber-框架'),
规格:[
'./features/*.feature'
],
黄瓜选项:{
要求:['./features/step_definitions /*.steps.js'],
标签:[],
严格:true,
格式:[ pretty],
dryRun:false,
编译器:[]
},
onPrepare:function(){
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);
var Expect = chai.expect;
module.exports = function(){
this.Given(/ ^我去([[^] *) $ /,function(site){
browser.get(site);
});
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'));
Expect(todoList.count())。to.ally.equal(3);
Expect(todoList.get(2).getText())。最终equal('Do Do Be Awesome')
.and.notify(callback);
});
};
在运行量角器Cucumber-conf.js
,我得到以下错误...
/ opt / protractor_tests
➔protractor黄瓜.config.js
(节点:3963)已弃用警告:os.tmpDir()已弃用。请改用os.tmpdir()。
[21:19:17] I /启动器-运行1个WebDriver实例
[21:19:17] I /托管-使用位于http:// localhost:4444 / wd /的硒服务器hub
功能:使用量角器
运行黄瓜方案:量角器和黄瓜测试
?鉴于我去了 https://angularjs.org/
?当我在任务字段
中添加很棒时?然后单击添加按钮
?然后,我应该在列表中看到我的新任务
警告:
1)场景:量角器和黄瓜测试-features / testone.feature:4
步骤:给我我去 https://angularjs.org/-features / testone.feature:5
消息:
未定义。使用以下代码段实现:
Given('我去{stringInDoubleQuotes}',函数(stringInDoubleQuotes,回调){
//在此处编写将上面的短语变成具体动作的代码
callback(null,'pending');
});
2)场景:量角器和黄瓜测试-features / testone.feature:4
步骤:当我在任务字段中添加 Be Awesome时-features / testone.feature:6
消息:
未定义。使用以下代码段实现:
When('我在任务字段中添加{stringInDoubleQuotes}',函数(stringInDoubleQuotes,callback){
//在此处编写代码,将上面的短语转换为具体动作
callback(null,'pending');
});
3)场景:量角器和黄瓜测试-features / testone.feature:4
步骤:然后单击添加按钮-features / testone.feature:7
消息:
未定义。用以下代码片段实现:
When('I click the add button',function(callback){
//在此处编写将上面的短语变成具体动作的代码
callback(null,'pending');
});
4)场景:量角器和黄瓜测试-features / testone.feature:4
步骤:然后,我应该在列表中看到我的新任务-features / testone.feature:8
消息:
未定义。用以下代码片段实现:
然后(我应该在列表中看到我的新任务,函数(回调){
//在此处编写代码,将上面的短语变成具体的动作
callback(null,'pending');
});
1个场景(1个未定义)
4个步骤(4个未定义)
0m00.000s
[21:19:22] I / launcher-0个实例的WebDriver仍在运行
[21:19:22] I /启动-chrome#01失败1次测试
[21:19:22] I / launcher-总体而言:1失败规范s)
[21:19:22] E / launcher-进程退出,错误代码为1
/ opt / protractor_tests
➔
由于执行错误而更新
[15:22:59] I /启动器-运行1个WebDriver
实例[15:22:59] I /托管-使用位于http:// localhost:4444 / wd /的硒服务器hub
功能:与量角器
一起运行黄瓜方案:量角器和黄瓜测试
√鉴于我去了 https://angularjs.org/
√何时我在任务字段
中添加很棒√然后单击添加按钮
×然后,我应该在列表
中看到我的新任务失败:
1)场景:量角器和黄瓜测试-特点:testone.feature:4
步骤:然后,我应该在列表中看到我的新任务-features\testone.feature:8
步骤定义:features\step_definitions\testone.steps.js:22
消息:
错误:函数在超时后的5000毫秒
后超时。< anonymous> (< local> \ProtractorTests\node_modules\cucumber\lib\user_code_runner.js:91:22)ontimeout上的
(timers.js:365:14)tryOnTimeout上的
(定时器.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 /启动器-总体:1个失败的规格
[15:23:19] E /启动器-进程退出,错误代码为1
错误命令失败,退出代码为1。
它正在尝试使用CucumberJS 2.0.0+语法-目前正在开发中。
可以将CucumberJS降级到1.3.1或更低版本,或者对您这样做步骤定义:
var chai = require('chai'),
Expect = chai.expect,
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var {defineSupportCode} = require('cucumber');
defineSupportCode(({Given,When,Then})= >> {
Given(/ ^我去([[^] *) $ /,function(site) {
return browser.get(site);
});
When(/ ^我在任务字段$ /中添加([^] *) function(task){
return element(by.model('todoList.todoText'))。sendKeys(task);
});
When(/ ^ I click添加按钮$ /,function(){
var el = element(by.css('[value = add]'));
return el.click();
});
然后(/ ^我应该在列表中看到新任务$ /,function(){
var todoList = element.all(by.repeater('todo in todoList .todos'));
Expect(todoList.count())。to。最终。等于(3);
返回期望(todoList.get(2).getText())。最终.equal('Do Be Be Awesome');
});
});
哪个是CucumberJS 2.0.0+语法
编辑
在CucumberJS 2.0.0中有两种设置超时的方法
默认超时
这是为您拥有的所有方案设置默认超时:
letcensingTimeout = 200 * 1000,
{defineSupportCode} = require('cucumber');
defineSupportCode(({setDefaultTimeout})=> {
setDefaultTimeout(scenarioTimeout);
});
在此示例中,我将方案超时设置为200秒。您可以将其更改为适合自己的感觉。
单个步骤
这是为了设置缓慢的超时时间:
When(/ ^我点击添加按钮$ /,{超时: 60 * 1000},function(){
var el = element(by.css('[value = add]'));
return 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\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.
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屋!