Skip to content

Data-Driven Scenarios ​

A Scenario Outline runs once for every row of its Examples table. Rather than typing that table into the feature, you can keep the data in a file and name the file on the Examples: line:

gherkin
Scenario Outline: Register <name>
  Given we are completing the registration eform
  When we set 'name' to '<name>'
  And we set 'age' to '<age>'
  Then 'summary' shows '<name>'

  Examples: users.csv

Leave out the table entirely. When the test set is run, Aire Assert reads users.csv and inserts its rows as the Examples table, so the outline above runs once per person in the file.

Adding the data file ​

Add the file to the Test Set's Files/ folder with Add File (see Repositories Tree View), the same folder used for file uploads. Name just the file on the Examples: line - folders are not supported.

Each column name becomes a placeholder, so a column called age fills <age> in the steps.

Supported formats ​

CSV ​

The first row holds the column names; every other row is one example. Values containing commas, quotes or line breaks can be wrapped in double quotes, with a quote inside written as "".

name,age,comment
Alice,30,
Bob,41,"Prefers ""Robert"", not Bob"

JSON ​

An array of objects. Each object is one example and each property a column. An object can leave a property out, and that cell is left empty.

json
[
  { "name": "Alice", "age": 30 },
  { "name": "Bob", "age": 41, "comment": "Prefers Robert" }
]

Numbers and true/false are used as written; null gives an empty cell. Property values must be single values, not nested objects or arrays.

XML ​

Each element directly inside the root element is one example. Its attributes and its child elements are the columns.

xml
<users>
  <user id="1">
    <name>Alice</name>
    <age>30</age>
  </user>
  <user id="2">
    <name>Bob</name>
    <age>41</age>
  </user>
</users>

Child elements must hold a single value, not further elements.

Things to know ​

  • Use either a file or a table, not both: an Examples: line that names a data file and also has a table under it stops the test run from starting.
  • | characters and line breaks in your data are handled for you.
  • Double quotes in your data are turned into single quotes, the same as anywhere else in a feature.
  • The test run fails to start if the file is missing, cannot be read, has no data rows, or has a CSV row with a different number of values from the header row. The error names the file.
  • You can have several Examples: blocks under one outline, each from a different file or table.