【问题标题】:Webdriverio cucumber cant use promisesWebdriverio黄瓜不能使用承诺
【发布时间】:2016-11-29 10:48:32
【问题描述】:

我正在尝试使用 webdriverIO 学习更多 cucumberjs,但在启动测试时遇到了一些麻烦。

其实,我想介绍一下这个简单的功能:

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(callback) 函数
  • 如果我通过在 .url(arg1) 之后添加 callback() 来绕过上一点,我会转到下一点
  • 在第一个然后中,第一个解决方案和第二个解决方案似乎都不起作用。当我尝试记录 const title 值时,我有一个未决的承诺。但是,当我尝试解决该承诺(第二种情况)时,我从不记录任何内容(即使在拒绝的情况下)。

约束

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

编辑:我总是遇到超时问题

【问题讨论】:

    标签: javascript node.js gherkin webdriver-io cucumberjs


    【解决方案1】:

    使用chimpjs。它集成了webdriverio,黄瓜,和其他朋友。它是“基于光纤的”,因此您可以主要以同步方式编写测试。我使用它,当我必须使用 Promise 时,我可以或需要使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-19
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      相关资源
      最近更新 更多