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

橙三吉。 提交于 2019-12-04 08:07:47

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;

In my case I've had to set the default timeout in the defineSupportCode, because trying to modify the timeout in the webdriver didn't provide any effect

defineSupportCode(function({Given, When, Then, setDefaultTimeout}) {

    setDefaultTimeout(60 * 1000);

    Given('I am on the Cucumber.js GitHub repository', function() {

Refer to this part of the doc

Replacing the this.Given in the step definitions with the syntax used for a promise, is what has fixed it for me on two different OSX environments.

Here is the promise syntax that works:

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.
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!