World对象
对于每个场景,都有一个独立的上下文叫World, 在hooks和步骤的运行函数中用this
来访问.
默认的 World 构造函数是:
JavaScript
function World({attach, parameters}) {
this.attach = attach
}
attach
: 用于将附件添加到hooks/步骤的函数
默认的对象可以被setWorldConstructor
覆盖.
JavaScript
const { setWorldConstructor } = require('cucumber');
const 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) {
let condition = seleniumWebdriver.until.elementLocated(locator);
return this.driver.wait(condition)
}
}
setWorldConstructor(CustomWorld)
注意: World构造函数在v0.8.0后是严格同步的.