Cucumber Support

API Reference

Each method can be obtained from the object returned by require('cucumber').


defineParameterType({name, preferForRegexpMatch, regexp, transformer, useForSnippets})

Define a new parameter type and optionally convert the output parameter to other parameters.

  • name: Used to quote this type of string in Cucumber expressions
  • regexp: regular expression (or regular expression array) matching the parameter
  • transformer: An optional function that converts captured parameters from strings to parameters passed to step definitions. If no conversion function is specified, the captured parameter will remain as a string. This function can be synchronous, or it can return the converted Promise value. The value pointed to by the this pointer is the current world object, so this function can be delegated to the function of the world object. World proxy functions cannot use arrow functions.
  • useForSnippets: The default is true. This means that this parameter type will be used to generate fragments with undefined steps. If regexp frequently matches text that you do not intend to use as a parameter, please use false to disable its use for generating snippet code.
  • preferForRegexpMatch: The default is false. If you use regular expressions and want the regexp corresponding to this parameter type to take precedence over other parameter types during matching, set it to true.

The built-in parameter types are

  • int
  • float
  • string
    • Enclosed in single or double quotes
    • transformer will remove the quotes
  • word

After([options,] fn)

Define hooks to run after each scenario.

  • options: objects with the following keys:
    • tags: String tag expression, used to apply this hook to certain scenarios only. For more information, see cucumber-tag-expressions
    • timeout: hook-specific timeout to override the default timeout.
  • fn: A function, defined as follows:
    • The first parameter will be an object with this format: {sourceLocation: {line, uri}, result: {duration, status}, pickle}
      • The pickle object comes from the gherkin library. Please refer to its structure example testdata/good/*.pickles.ndjson.
    • When using the asynchronous callback interface, a parameter listed at the end can be provided as the callback function.

options can also be a string as a shorthand to specify the tag tags.

Execute them in the reverse order in which they define multiple After hooks.


AfterAll([options,] fn)

Define hooks to run after all scenarios are completed.

  • options: objects with the following keys:
    • timeout: hook-specific timeout to override the default timeout.
  • fn: A function, defined as follows:
    • When using the asynchronous callback interface, there is a callback function parameter.

Execute them in the reverse order in which they define multiple AfterAll hooks.


Before([options,] fn)

Define hooks to run before each scenario. Same as the After hook, except that the first one passed to fn does not have the result attribute.

Multiple Before hooks are executed in the order in which they are defined.


BeforeAll([options,] fn)

Define hooks that run before all scenarios. It has the same interface as AfterAll.

Multiple BeforeAll hooks are executed in the order in which they are defined.


defineStep(pattern[, options], fn)

Define a step.

Aliases: Given, When, Then.

  • pattern: A regular expression or string pattern for matching with the gherkin step.
  • options: objects with the following keys: -timeout: Step-specific timeout to override the default timeout. -wrapperOptions: step-specific options passed to define function wrappers
  • fn: A function, which should be defined as follows: -There should be a parameter match for each capture in the regular expression. -If the Cucumber step has a docstring or data sheet, there will be an additional parameter. -When using the asynchronous callback interface, the last parameter is the callback function.

Given(pattern[, options], fn)

Alias ​​defineStep.


setDefaultTimeout(milliseconds)

Set the default timeout period for asynchronous steps. The default is 5000 milliseconds.


setDefinitionFunctionWrapper(fn, options)

Set up a function to wrap the step/hook definition. When used, the result will be packaged again to ensure that it is the same length as the original step/hook definition. options is specific to the step wrapperOptions and can be undefined.


setWorldConstructor(constructor)

Set a custom world constructor to override the default world constructor:

JavaScript
function World({attach, parameters}) {
  this.attach = attach
  this.parameters = parameters
}

  • attach-can be used to add attachments in a function hook/step definition
  • parameters-world parameters passed in through the command line

Note: The World constructor is strictly synchronized after v0.8.0.


Then(pattern[, options], fn)

Alias ​​of defineStep.


When(pattern[, options], fn)

Alias ​​of defineStep.

Chinese version click here.

results matching ""

    No results matching ""