CucumberJS - 错误:在 Timer.listOnTimeout (timers.js:92:15) 5000 毫秒后步骤超时 [英] CucumberJS - Error: Step timed out after 5000 milliseconds at Timer.listOnTimeout (timers.js:92:15)
问题描述
我是 Cucumberjs 的新手,只是第一次尝试运行一个功能.我已经在 cucumber-js github 页面 上构建了该功能.尝试运行时出现此错误:
<块引用>Benjamins-MBP:Features Ben$cucumber.js example.feature 特性:示例功能
作为cucumber.js 的用户,我想拥有关于cucumber 的文档这样我就可以专注于构建出色的应用程序
场景:阅读文档#示例.特征:6鉴于我在 Cucumber.js GitHub 存储库 # StepDefinitions/myStepDefinition.js:4错误:步骤在 5000 毫秒后超时在 Timer.listOnTimeout (timers.js:92:15)当我转到 README 文件时 # StepDefinitions/myStepDefinition.js:15然后我应该看到Usage"作为页面标题# StepDefinitions/myStepDefinition.js:22
失败场景:example.feature:6 # 场景:阅读文档
1 个场景(1 个失败)3 个步骤(1 个失败,2 个跳过)0m05.001s
考虑到它是cucumber-js github页面上的示例特性,所以人们会怎么做才能让这个特性通过?
代码如下:
//features/step_definitions/myStepDefinitions.jsmodule.exports = 函数 () {this.Given(/^我在Cucumber.js GitHub仓库$/, function (callback) {//用你想要的代码表达上面的正则表达式.//`this` 设置为 World 实例.//即您可以使用 this.browser 来执行该步骤:this.visit('https://github.com/cucumber/cucumber-js', 回调);//回调被传递给visit(),以便当作业完成时,下一步可以//由 Cucumber 执行.});this.When(/^我去自述文件$/, function (callback) {//用你想要的代码表达上面的正则表达式.最后调用 callback()//步骤,或 callback.pending() 如果步骤尚未实现:回调.pending();});this.Then(/^I 应该看到 "(.*)" 作为页面标题$/, function (title, callback) {//匹配的组作为参数传递给步骤定义var pageTitle = this.browser.text('title');if (title === pageTitle) {打回来();} 别的 {回调(新错误(预计在标题页面上" + 标题));}});};
特点:
Feature:示例功能作为cucumber.js 的用户我想要关于黄瓜的文件这样我就可以专注于构建很棒的应用程序场景:阅读文档鉴于我在 Cucumber.js GitHub 存储库上当我转到 README 文件时然后我应该看到用法"作为页面标题
world.js 文件:
//features/support/world.jsvar 僵尸 = require('僵尸');函数世界(){this.browser = 新僵尸();//this.browser 将在步骤定义中可用this.visit = 函数(网址,回调){this.browser.visit(url, callback);};}module.exports = function() {this.World = 世界;};
添加这个以删除 5000 毫秒:
protractor.conf.js
cucumberOpts: {要求: ['测试/e2e/support/env.js','main.step.js',...],格式:'漂亮',//或摘要保持活动:假},
env.js
var configure = function () {this.setDefaultTimeout(60 * 1000);};module.exports = 配置;
<块引用>
示例:
test.feature
特性:测试我要测试等待场景:测试呼叫等待鉴于我等待6"秒
main.step.js
module.exports = function () {this.World = require(__base +'tests/e2e/support/world.js').World;//我等待{time}"秒this.Given(/^I wait "?([^"]*)"? seconds$/, function (time) {返回 browser.sleep(time * 1000);});};
world.js
var World, chai, chaiAsPromised;柴 = 要求('柴');chai_as_promised = require('chai-as-promised');世界 = 函数世界(回调){chai.use(chai_as_promised);this.expect = chai.expect;打回来();};module.exports.World = World;
I'm new to cucumberjs and just trying out my first attempt at running a feature. I've built the feature that is on the cucumber-js github page. I get this error when trying to run it:
Benjamins-MBP:Features Ben$ cucumber.js example.feature Feature: Example feature
As a user of cucumber.js I want to have documentation on cucumber So that I can concentrate on building awesome applications
Scenario: Reading documentation # example.feature:6 Given I am on the Cucumber.js GitHub repository # StepDefinitions/myStepDefinition.js:4 Error: Step timed out after 5000 milliseconds at Timer.listOnTimeout (timers.js:92:15) When I go to the README file # StepDefinitions/myStepDefinition.js:15 Then I should see "Usage" as the page title # StepDefinitions/myStepDefinition.js:22
Failing scenarios: example.feature:6 # Scenario: Reading documentation
1 scenario (1 failed) 3 steps (1 failed, 2 skipped) 0m05.001s
What would one do to try to make this feature pass, given it is the example feature on the cucumber-js github page so probably not incorrect?
Here is all the code:
// features/step_definitions/myStepDefinitions.js
module.exports = function () {
this.Given(/^I am on the Cucumber.js GitHub repository$/, function (callback) {
// Express the regexp above with the code you wish you had.
// `this` is set to a World instance.
// i.e. you may use this.browser to execute the step:
this.visit('https://github.com/cucumber/cucumber-js', callback);
// The callback is passed to visit() so that when the job's finished, the next step can
// be executed by Cucumber.
});
this.When(/^I go to the README file$/, function (callback) {
// Express the regexp above with the code you wish you had. Call callback() at the end
// of the step, or callback.pending() if the step is not yet implemented:
callback.pending();
});
this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) {
// matching groups are passed as parameters to the step definition
var pageTitle = this.browser.text('title');
if (title === pageTitle) {
callback();
} else {
callback(new Error("Expected to be on page with title " + title));
}
});
};
The feature:
Feature: Example feature
As a user of cucumber.js
I want to have documentation on cucumber
So that I can concentrate on building awesome applications
Scenario: Reading documentation
Given I am on the Cucumber.js GitHub repository
When I go to the README file
Then I should see "Usage" as the page title
the world.js file:
// features/support/world.js
var zombie = require('zombie');
function World() {
this.browser = new zombie(); // this.browser will be available in step definitions
this.visit = function (url, callback) {
this.browser.visit(url, callback);
};
}
module.exports = function() {
this.World = World;
};
Add this to remove the 5000 milliseconds :
protractor.conf.js
cucumberOpts: {
require: [
'tests/e2e/support/env.js',
'main.step.js',
...
],
format: 'pretty', // or summary
keepAlive: false
},
env.js
var configure = function () {
this.setDefaultTimeout(60 * 1000);
};
module.exports = configure;
example :
test.feature
Feature: test
I want test wait
Scenario: Test call wait
Given I wait "6" seconds
main.step.js
module.exports = function () {
this.World = require(__base +'tests/e2e/support/world.js').World;
// I wait "{time}" seconds
this.Given(/^I wait "?([^"]*)"? seconds$/, function (time) {
return browser.sleep(time * 1000);
});
};
world.js
var World, chai, chaiAsPromised;
chai = require('chai');
chai_as_promised = require('chai-as-promised');
World = function World (callback) {
chai.use(chai_as_promised);
this.expect = chai.expect;
callback();
};
module.exports.World = World;
这篇关于CucumberJS - 错误:在 Timer.listOnTimeout (timers.js:92:15) 5000 毫秒后步骤超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!