Contents

Step Wrapper with Options

In order to be able to write more complex step definition wrappers As a developer I want Cucumber to provide the "options" object to the wrapping function

Scenario: options passed to the step definitions wrapper

@spawn

  • Given a file named "features/a.feature" with:
    gherkin
    Feature: Step with an option
      Scenario: Steps
        When I run a step with options
  • And a file named "features/step_definitions/cucumber_steps.js" with:
    ruby
    const {When} = require('@cucumber/cucumber')
    
    When(/^I run a step with options$/, {wrapperOptions: {retry: 2}}, function () {})
  • And a file named "features/support/setup.js" with:
    ruby
    const {setDefinitionFunctionWrapper} = require('@cucumber/cucumber')
    
    setDefinitionFunctionWrapper(function (fn, options = {}) {
      if (options.retry) {
        console.log("Max retries: ", options.retry);
      }
      return fn;
    })
  • When I run cucumber-js
  • Then the output contains the text:
    text
    Max retries: 2

Source: features/step_wrapper_with_options.feature at commit 3ac6ecda, Cucumber Js (MIT license).