Gherkin input format
Gherkin is the Given/When/Then language of Cucumber and other behavior-driven development tools. Doc Detective reads .feature files with no configuration. Each scenario runs as a test, and each step phrase maps to a Doc Detective action. You don’t write step definitions or install Cucumber.
File extensions
Doc Detective processes Gherkin files with the .feature extension.
To read files with another extension as Gherkin, add a file type that extends gherkin to fileTypes in your config file:
A fileTypes list in your config replaces the default list. If your config already sets fileTypes, add "gherkin" to it to keep reading .feature files.
How scenarios become tests
- Each
.featurefile is a spec. - Each
Scenario(orExample) is a test. Its name is the test’stestIdanddescription. Backgroundsteps run at the start of every scenario in the file. ABackgroundinside aRuleruns after the file’sBackground, in that rule’s scenarios only.- A
Scenario Outline(orScenario Template) runs once per row of itsExamples(orScenarios) tables. Each<name>placeholder takes the row’s value, in step text, doc strings, and table cells. Each row’stestIdis the scenario name plus[row N], counting from 1 across all of the outline’sExamples. Rulegroups scenarios. Its tags andBackgroundapply to the scenarios inside it.
To filter scenarios with --test, use the scenario name, or set your own ID with an @id: tag.
Keywords must be in English.
Step phrases
With step detection on, which is the default, each step’s text after Given, When, Then, And, But, or * maps to an action:
I run: makes a runCode step, which is unsafe, so it runs only with allowUnsafeSteps.
A step that matches no phrase doesn’t run, and Doc Detective warns:
The rest of the scenario still runs. To run something there, add a # step statement, or add your own phrase in a file type that extends gherkin. Each phrase is a markup entry that matches element nodes with the tag step, and its regex runs on the step text without its keyword:
See Custom inputs for how markup entries merge.
Doc strings and data tables
A doc string (""" or ```) after I run:, a with: request, or returns: is the code, the request body, or the mocked body. Text after the opening """, such as bash or json, is the media type:
A data table after I fill in: types each row’s value into the row’s selector. A one-column table after I should see: finds each row’s text:
A selector can contain double quotes, such as [name="email"]. A value can’t. Doc Detective warns about that row and doesn’t type it, so use a # step comment with a type step instead.
Tags
Tags on a Feature, Rule, Scenario, or Examples table apply to everything inside it.
Browser and platform tags set the test’s runOn, which replaces the contexts in your config for that scenario. Other tags have no effect.
Emulation steps
These steps set how the page sees the browser instead of running an action:
They apply to the whole scenario, wherever they appear in it, and a Background sets them for every scenario. With no browser tag, the scenario runs in Chrome, the one browser that supports every setting. A browser that can’t apply a setting skips the scenario’s context. See page emulation for what each browser supports.
Combine browser tags with emulation steps to run one file across browsers and settings:
Inline statements
Gherkin comments hold inline statements:
# step {...}adds a step where it sits in the scenario.# test {...}above a scenario, or above its tags, adds settings to that scenario’s test. Its keys win over the ones tags set.# test ignore startand# test ignore endskip the steps between them, including emulation steps. A block covers steps inside one scenario. To skip steps in several scenarios, put a block in each.
Each scenario is already a test, so it needs no # test end. Gherkin statements take JSON only.
To run only the inline statements, turn off step detection with detectSteps: false in your config, or with # test {"detectSteps": false} above a scenario. Step phrases then don’t run or warn.
Warnings
An outline with no Examples and a scenario with no steps don’t run.
Next steps
- See inline tests for every statement.
- See Custom inputs to add or change step phrases.
- See platforms and browsers for contexts and emulation.