Skip to content

Use variables with a Gherkin Script

Using variables with a Gherkin script enables you to replay a scenario as many times as the number of datasets it contains.

To introduce variables to a Gherkin script, you need to use different keywords, parameters, and datasets directly integrated in the script. The keyword Scenario Outline indicates that the scenario contains examples, in other words parameters and datasets.

In the script, the parameters are defined by being written in between the characters < and >. There can be as many parameters as you want. Then, these parameters must be inserted into a data table.

Before inserting a data table, the keyword Examples must appear to indicate the existence of this data table. The data table is in the form of a table with as many columns as there are parameters in the script. This table's heading contains in each column the name of the parameters as written in the script. Each row corresponds to a dataset that will be played during the execution.

Focus

The name of the parameters in the heading of the datatable must be written the same way as they are in the script. The letter cases must be the same too, otherwise the parameters will not be taken into account and will not be displayed during the execution.

Gherkin script with variables

During the execution, for an automatic execution, the script is automatically replayed for each dataset. For a manual execution, a test step is created for each dataset in the execution. In the execution plan, contrarily to BDD test cases, there is not one test plan item per dataset, but only one item in total. During the execution of this item, the execution scenario displays as many test steps as there are datasets in the script's data table.

Gherkin script test step with settings