2016-11-29 58 views
4

我試圖通過webdriverIO學習更多的cucumberjs,並且在啓動我的測試時遇到了一些麻煩。Webdriverio黃瓜不能使用承諾

其實,我要蓋這個簡單的功能:

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. 

有了這個測試:

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

我的配置文件:

"use strict"; 

const WebDriverIO = require('webdriverio'); 
const browser = WebDriverIO.remote({ 
    baseUrl: 'https://google.com', // Or other url, e.g. 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(回調)函數傳遞
  • 如果我剛好經過的.url(Arg1)將加入回調()繞過前面的點 ,我轉到下一點
  • 在第一個然後,第一個解決方案和第二個解決方案似乎都不起作用。雖然我試圖記錄常量標題值,但我有一個未決的承諾。但是,當我試圖解決這個承諾時(第二種情況),我從不記錄任何東西(即使在拒絕的情況下)。

約束

  • 我不想使用wdio
  • 我米用硒2.53
  • 我爲使用我米使用we​​bdriverio 4.4 cucumberjs 1.3.1
  • 。 0
  • 我使用Nodejs v4.6.0

編輯:我總是有超時問題

回答

0

使用chimpjs。它集成了webdriverio,黃瓜和其他朋友。這是「在光纖上」,所以你可以編寫你的測試主要是以同步的風格。我使用它,當我必須使用我可以或需要的承諾時。