World对象
对于每个场景,都有一个独立的上下文叫World, 在hooks和步骤的运行函数中用this
来访问.默认的 world 构造函数是:
function World({attach, parameters}) {
this.attach = attach
this.parameters = parameters
}
默认的对象可以被setWorldConstructor
覆盖.
var {setWorldConstructor} = require('cucumber');
var seleniumWebdriver = require('selenium-webdriver');
function CustomWorld() {
this.driver = new seleniumWebdriver.Builder()
.forBrowser('firefox')
.build();
// Returns a promise that resolves to the element
this.waitForElement = function(locator) {
var condition = seleniumWebdriver.until.elementLocated(locator);
return this.driver.wait(condition)
}
}
setWorldConstructor(CustomWorld)
注意: World构造函数在v0.8.0后是严格同步的.