【发布时间】: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