How to use a CSV file as a Scenario Outline data source

How to use a CSV file as a Scenario Outline data source

With the enhancements to Scenario Outlines, it is now possible to use multiple sources for test parameter data. Previously, parameters were set in the Feature in an Examples section specified and maintained by the user. The addition of Example Row, CSV, SQL, MOCA, and Datastore sources provide more dynamic permutations and less maintenance.

This article details what the CSV Examples data source is, as well as why and how to use it.

What are CSV Examples?

CSV Examples is the keyword used in Scenario Outlines to use a Comma Separated Value file as test parameters to be used in execution. The CSV file must contain a parameter header row and those names will become the Cycle variable names. Each row in the CSV file will generate an iteration of the Scenario Outline


Scenario Outline: CSV Test
CSV Examples:datasets\clients.csv
Then I echo <client_id>
Then I echo <adr_id>

Why use a CSV file?

CSV is an commonly utilized file format. CSV files for test parameter data can be used to iterate through many rows of static data. This file can be created manually or exported from another system to swiftly create many test permutations. CSV files are easily edited and maintained, small in size and usually do not require special connections or credentials to use.

How to use CSV files?

CSV files are used with the keyword Scenario Outline: and declared on the line immediately following Scenario Outline.

The CSV Examples keyword requires a file path relative to the Project directory path with a valid CSV file. In the example above we provided datasets\clients.csv as the path. The full path would be similar to C:\Cycle\PROJECT_DIR\datasets\clients.csv with PROJECT_DIR being the example Project directory.

The CSV Examples line is followed by the Scenario execution steps.

When the Scenario Outline is executed Cycle converts the header row into variable names as chevron variables and the subsequent data rows as the values to use in the Steps. Each row in the CSV will be an iteration of the Scenario Outline executions steps.

For example if you have a CSV file formatted like:


then Steps use the chevron and variable replacement to use the information provided.

Given I open <browser> web browser

Then I navigate to <site> in web browser

When the Step executes <browser> will be replaced with Chrome and <site> will be replaced with

In this specific example the Scenario Outline would only iterate once since there is only one data value row. Below is an example of a Scenario Outline that would iterate twice.


Putting it all together

In this example, the Steps are designed to validate whether the text in the element on the web page matches the expected value. The goal is to execute this for all the data rows in our CSV file. This particular example checks 4 different element text values on the Tryon Home Page.

CSV File contents:

Chrome,,id:et-info-phone,(888) 256-2177
Chrome,,id:menu-item-51,REQUEST A QUOTE
Chrome,,id:menu-item-502,SOFTWARE & SERVICES

Scenario Outline example:

Scenario Outline: Validate Tryon Home Page Text Elements
CSV Examples: datasets\elements.csv
Given I open <browser> web browser
Then I navigate to <site> in web browser
Then I maximize web browser
Then I see <value> matches all text in element <element> in web browser within 5 seconds
Then I close web browser

The Output in the Output Panel shows each Example numbered individually for troubleshooting.