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

Example:

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:

browser,site
Chrome,https://cyclelabs.io/playground/#!/main/orders

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 https://cyclelabs.io/playground/#!/main/orders.

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.

browser,site
Chrome,https://cyclelabs.io/playground/#!/main/orders
Chrome, https://www.google.com

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 Cycle Labs Grocer.io Page.

CSV File contents:

browser,site,element,value
Chrome,https://cyclelabs.io/playground/#!/main/orders,className:name,Courtney Montgomery
Chrome,https://cyclelabs.io/playground/#!/main/orders,className:header,Orders   
Chrome,https://cyclelabs.io/playground/#!/main/orders,xPath://div[@webix_tm_id == 'inventory']/span,Inventory
Chrome,https://cyclelabs.io/playground/#!/main/orders,xPath://div[@webix_tm_id = 'rewards']/span,Rewards

Scenario Outline example:

Scenario Outline: Validate Grocer.IO 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.

mceclip0.png


    • Related Articles

    • How to use MOCA Examples 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, ...
    • How to use a SQL query 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, ...
    • How to use Example Row 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, ...
    • What improvements to Scenario Outlines should I be aware of?

      What do we know about Scenario Outlines? Scenario Outlines are similar to regular Scenarios except that a Scenario Outline executes multiple times, once for each row of data it is using. What is staying the same? The keyword Scenario Outline: The ...
    • How to load and clean up test data efficiently in Cycle.

      Problem In order to properly evaluate system behavior it is required that known inputs produce desired outputs. This is especially critical when working with the JDA WMS due to its multitude of configuration options that drive specific system ...