CucumberJS-错误:步骤在Timer.listOnTimeout(Timer.js:92:15)5000毫秒后超

CucumberJS - Error: Step timed out after 5000 milliseconds at Timer.listOnTimeout (timers.js:92:15)

本文关键字:Timer 5000毫 错误 CucumberJS- listOnTimeout js      更新时间:2023-09-26

我是cucumberjs的新手,刚刚尝试运行一个功能。我已经构建了cucumber js github页面上的功能。我在尝试运行它时遇到这个错误:

Benjamins MBP:特写Ben$cucumber.js example.feature特写:示例功能

作为cucumber.js的用户,我想拥有关于cucumber的文档这样我就可以集中精力构建出色的应用程序

场景:阅读文档#示例。特征:6假设我在Cucumber.js GitHub存储库#StepDefinitions/myStepDefinition.js:4错误:步骤在5000毫秒后超时在Timer.listOnTimeout(times.js:92:15)当我转到自述文件#StepDefinitions/myStepDefinition.js:15时然后我应该看到"用法"作为页面标题#StepDefinitions/myStepDefinition.js:22

失败场景:示例。功能:6#场景:阅读文档

1个场景(1个失败)3个步骤(1个故障,2个跳过)0m05.001s

考虑到这是cucumber js github页面上的示例功能,所以可能不会出错,我们会怎么做才能让这个功能通过呢?

这是所有的代码:

    // 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));
    }
  });
};

特点:

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

world.js文件:

// 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;
};

添加此项可删除5000毫秒:

量角器.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;

示例:

测试功能

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;

在我的情况下,我不得不在defineSupportCode中设置默认超时,因为试图修改网络驱动程序中的超时没有提供任何效果

defineSupportCode(function({Given, When, Then, setDefaultTimeout}) {
    setDefaultTimeout(60 * 1000);
    Given('I am on the Cucumber.js GitHub repository', function() {

请参阅文档的这一部分

promise使用的语法替换步骤定义中的this.Given,这是我在两个不同的OSX环境中修复它的原因。

以下是有效的promise语法:

this.Given(/^I am on the Cucumber.js GitHub repository$/, function () {
  // Notice how `callback` is omitted from the parameters
  return this.visit('https://github.com/cucumber/cucumber-js');
  // A promise, returned by zombie.js's `visit` method is returned to Cucumber.
});