2015-12-22 143 views
4

我是cucumberjs的新手,只是嘗試了第一次嘗試運行功能。我已經構建了cucumber-js github page上的功能。我在嘗試運行它時,這個錯誤:CucumberJS - 錯誤:在Timer.listOnTimeout(timers.js:92:15)5000毫秒後超時步驟

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

什麼會做一個儘量使此功能傳球,給了它是黃瓜,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; 
}; 

回答

3

的語法替換步驟定義this.Given用於promise,是什麼修復了我在兩個不同的OSX環境NTS。

這裏是承諾語法的工作原理:

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

剛剛從刪除回調參數證明對我來說足夠了。 – shashi

7

添加此按鈕,刪除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; 

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; 
+0

你在哪裏調用你在'env.js?'中導出的配置?' –

+0

不要緊,它不工作,因爲對我的env文件的引用不正確。配置被自動調用() –

4

在我來說,我不得不設置在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

相關問題