Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.2 KB

world.md

File metadata and controls

39 lines (30 loc) · 1.2 KB

World

World is an isolated context for each scenario, exposed to the hooks and steps as this. The default world constructor is:

function World({ attach, log, parameters }) {
  this.attach = attach
  this.log = log
  this.parameters = parameters
}
  • attach: function used for adding attachments to hooks/steps
  • log: function used for logging information from hooks/steps
  • parameters: object of parameters passed in via the CLI

The default can be overridden with setWorldConstructor:

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) {
    const condition = seleniumWebdriver.until.elementLocated(locator)
    return this.driver.wait(condition)
  }
}

setWorldConstructor(CustomWorld)

Note: The World constructor was made strictly synchronous in v0.8.0.