Demo
GUIDE

Feature-file grammar

4 MIN READ

Structure

gherkin
Feature: <business capability>

  Scenario: <actor performs an observable outcome>
    Given <starting state>
    When <primary action>
    And <supporting interaction>
    Then <observable business result required by this testcase>
    And <another required business assertion, when applicable>

Use Given for starting state, When for actions, and Then only for assertions that define whether the testcase passes.

Do not add a Then after every click, fill, search, set, select, upload, download, navigation, or data-capture action. A scenario may contain several actions followed by one meaningful Then — or no Then at all when its sole purpose is to prepare data for another testcase.

When later work merely depends on the page being ready, use an operational wait instead of turning readiness into an assertion:

gherkin
When I click the "New Account" button
And I wait until the "New Account" modal is ready
And I fill [$.testdata.account.name] in the "Account Name" text field
And I click the "Save" button
Then the Account record page should show [$.testdata.account.name]

Variables

gherkin
Given the created Account record page is open
When I save the current Account record URL as [$.output.record_url]
Variable Holds
[$.environment.<profile>.<field>] Environment configuration
[$.testdata.<dataset>.<field>] Test inputs
[$.output.<name>] Values created during execution
[$.input.<name>] A value supplied to the current testcase, including an output from an earlier testcase in the same testsuite

Cross-testcase values and files

A testcase publishes a reusable value or file with an output variable. A later testcase receives that output through its own input variable. Keep the feature syntax simple: the testsuite owns the output-to-input mapping.

Producer testcase:

gherkin
When I click the "Download Customer Export" button
And I save this file as [$.output.customer_export]

Consumer testcase:

gherkin
When I read data as CSV from [$.input.customer_export]
Then the CSV should contain a row for customer [$.testdata.customer.id]

The same handoff applies to other file types — use the reader that matches the file's meaning:

gherkin
When I read data as JSON from [$.input.api_export]
When I read data as Excel from [$.input.financial_workbook]
When I read text from [$.input.application_log]
When I upload [$.input.signed_contract] using the "Upload Files" control

Use [$.output.<name>] only in the producing testcase and [$.input.<name>] in the consuming one. Do not expose machine paths, copy file contents into feature text, or make the consumer locate another testcase's working directory.

Runtime-unique test data

Use a runtime timestamp when a test creates data that must be unique across scenarios or repeated runs. The timestamp is appended to a fixed, user-provided value; it is not literal text and it does not replace the meaningful prefix.

These two forms express the same pattern:

gherkin
When I fill "Automation Account {timestamp}" in the "Account Name" text field
When I fill "Automation Account " + current_timestamp in the "Account Name" text field

In both forms:

  • Automation Account is the stable value supplied by the author.
  • {timestamp} or current_timestamp is generated during execution.
  • The resolved value is a unique name such as Automation Account 20260810154530123.
  • Generate a fresh value for each scenario or test case that creates independent data.
  • Resolve the timestamp once for that logical value and reuse the exact result in later steps, assertions, lookups, and cleanup.
  • Save the resolved value as an output when another scenario or workflow must reference it.
gherkin
When I fill "Automation Account {timestamp}" in the "Account Name" text field
And I save the filled Account Name as [$.output.account_name]
And I click the "Save" button
Then the Account record page should show [$.output.account_name]

NEVER

Do not write a bare timestamp without the customer-readable prefix, and do not generate a second timestamp when referring to a record that was already created with the first one.

Exact text

Quote exact visible strings:

gherkin
When I click the "Save" button
Then I should see the heading "Account Details"

Keep actions unquoted:

gherkin
When I open the Accounts navigation item

Human-only instructions

gherkin
;skip; This record is created only in the authorized test environment.

;skip-start;
Business context for the author or reviewer.
These lines are not executed.
;skip-end;

Do not place required actions or assertions inside skipped text.