Webdriverio黄瓜不能使用承诺

我试图用webdriverIO学习更多的cucumberjs,并且在启动testing时遇到一些麻烦。

其实我想涵盖这个简单的function:

Feature: Example Feature In order to become productive As a test automation engineer I want to understand the basics of cucumber Scenario: My First Test Scenario Given I have open "https://google.com" Then the title should be "Google". And the bar should be empty. 

有了这个testing:

 const assert = require('assert'); module.exports = function() { this.Given(/^I have open "([^"]*)"$/, function(arg1, callback) { browser .url(arg1) .call(callback); }); this.Then(/^the title should be "([^"]*)"\.$/, function(arg1, callback) { // First solution const title = browser.getTitle(); assert(title, arg1); // Second solution browser .getTitle() .then(title2 => { assert(title2, arg1); callback(); }); }); this.Then(/^the bar should be empty\.$/, function(callback) { // Write code here that turns the phrase above into concrete actions callback(null, 'pending'); }); } 

我的configuration文件:

 "use strict"; const WebDriverIO = require('webdriverio'); const browser = WebDriverIO.remote({ baseUrl: 'https://google.com', // Or other url, eg localhost:3000 host: 'localhost', // Or any other IP for Selenium Standalone port: 4444, waitforTimeout: 120 * 1000, logLevel: 'silent', screenshotPath: `${__dirname}/documentation/screenshots/`, desiredCapabilities: { browserName: process.env.SELENIUM_BROWSER || 'chrome', }, }); global.browser = browser; module.exports = function() { this.registerHandler('BeforeFeatures', function(event, done) { browser.init().call(done); }); this.registerHandler('AfterFeatures', function(event, done) { browser.end().call(done); }); }; 

我的问题

我的问题是:

  • 我从来没有传入.call(callback)函数
  • 如果我通过在.url(arg1)之后joincallback()来绕过以前的观点,我会转到下一个点
  • 在第一个然后 ,第一个解决scheme和第二个解决scheme似乎都不起作用。 当我试图logging常量标题值,我有一个未决的承诺。 但是,当我试图解决这个承诺(第二种情况),我从来没有logging任何东西(即使在拒绝的情况下)。

约束

  • 我不想用wdio
  • 我使用selenium2.53
  • 我使用cucumberjs 1.3.1
  • 我使用webdriverio 4.4.0
  • 我正在使用Nodejs v4.6.0

编辑:我总是有超时问题

使用chimpjs 。 它集成了webdriverio,黄瓜和其他朋友。 这是“光纤”,所以你可以编写你的testing主要是在一个同步的风格。 我使用它,当我必须使用承诺,我可以或需要。