World对象

对于每个场景,都有一个独立的上下文叫World, 在hooks和步骤的运行函数中用this来访问. 默认的 world 构造函数是:

function World({attach, parameters}) {
  this.attach = attach
  this.parameters = parameters
}
  • attach: 用于将附件添加到hooks/步骤的函数
  • 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后是严格同步的.

results matching ""

    No results matching ""