【问题标题】:CucumberJS - Error: Step timed out after 5000 milliseconds at Timer.listOnTimeout (timers.js:92:15)CucumberJS - 错误:在 Timer.listOnTimeout (timers.js:92:15) 5000 毫秒后步骤超时
【发布时间】:2015-12-22 06:27:56
【问题描述】:

我是 cucumberjs 的新手,只是尝试我第一次尝试运行一项功能。我已经构建了cucumber-js github page 上的功能。尝试运行时出现此错误:

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

作为 cucumber.js 的用户,我希望获得有关 cucumber 的文档 这样我就可以专注于构建出色的应用程序

场景:阅读文档# example.feature: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.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;
};

【问题讨论】:

    标签: javascript timer cucumberjs


    【解决方案1】:

    添加这个以删除 5000 毫秒:

    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;
    

    示例:

    test.feature

    Feature: test
        I want test wait
    
        Scenario: Test call wait
            Given I wait "6" seconds
    

    ma​​in.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;
    

    【讨论】:

    • 你在哪里调用你在env.js?中导出的配置
    • 没关系,由于我对 env 文件的引用不正确,它无法正常工作。配置被自动调用()
    【解决方案2】:

    在我的例子中,我不得不在 defineSupportCode 中设置默认超时,因为尝试在 webdriver 中修改超时并没有提供任何效果

    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

    【讨论】:

      【解决方案3】:

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

      这是有效的承诺语法:

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

      【讨论】:

      • 仅从参数中删除回调对我来说就足够了。
      猜你喜欢
      • 1970-01-01
      • 2020-08-24
      • 2014-03-19
      • 2020-05-13
      • 2022-06-14
      • 2020-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多