dex*_*dex 11 protractor cucumberjs
从0.20.1开始, Cucumber现在在Protractor中得到了完全支持,但我正在努力寻找有关如何正确配置它的任何文档.知道如何设置world.js吗?
我在https://github.com/whyvez/angular-cucumber-example/blob/master/features/support/world.coffee找到了这个例子,但我不确定你是否还需要指定所有的需求模块和配置作为量角器配置文件(referenceConf.js)将拥有所有这些信息.
assert = require 'assert'
path = require 'path'
protractor = require 'protractor'
webdriver = require 'selenium-webdriver'
driver = new webdriver.Builder().
usingServer('http://localhost:4444/wd/hub').
withCapabilities(webdriver.Capabilities.chrome()).
build()
driver.manage().timeouts().setScriptTimeout(100000)
ptor = protractor.wrapDriver driver
class World
constructor: (callback) ->
@browser = ptor
@By = protractor.By
@assert = assert
callback()
module.exports.World = World
Run Code Online (Sandbox Code Playgroud)
Ped*_*pez 13
我创建了一个示例项目来展示如何使用Cucumber配置Protractor并使用World.
世界是一个分享不同场景之间共性的地方,这样您就可以使代码保持井井有条.
实际上,您只需要在/ features下名为/ support的文件夹中创建world.js文件.你也可以把你的钩子放在那里.您的步骤定义中将提供每个属性或功能.
world.js:
module.exports = function() {
this.World = function World(callback) {
this.prop = "Hello from the World!";
this.greetings = function(name, callback) {
console.log("\n----Hello " + name);
callback();
};
callback();
}
Run Code Online (Sandbox Code Playgroud)
然后在你的步骤:
var sampleSteps = function() {
this.Given(/^this is the first sample$/, function (callback) {
console.log("\n----" + this.prop);
callback();
});
this.Given(/^this is the second sample$/, function (callback) {
this.greetings("everybody", callback);
});
};
module.exports = sampleSteps;
Run Code Online (Sandbox Code Playgroud)
你的protractor.js配置文件看起来像这样:
exports.config = {
specs: [
'e2e/features/*.feature'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8081/',
framework: 'cucumber',
};
Run Code Online (Sandbox Code Playgroud)
这是GitHub存储库.
https://github.com/plopcas/st-protractor-cucumber
希望这可以帮助.