How to Parameterize Tests (Taurus YAML Scripts)

In GUI functional testing, sometimes you may want to parameterize your test to use external data instead values hard-coded in the test body. You can upload a CSV file with data that you want to inject to your test.

This article covers parameterizing test data in a Taurus YAML script. Alternatively, you can also Parameterize Test Data in Scriptless Tests.

This article covers the following topics:

  1. Precondition
  2. Create data-provider file
  3. Upload file to BlazeMeter
  4. Refactor the test to use data from the file
  5. Run test

Precondition

In this scenario, we have a test as a YAML file. The test goes to the http://blazedemo.com site, then selects values in two dropdowns, submits the selection and, finally, asserts that the next page appears with the expected header:

modules:
nose:
ignore-unknown-actions: true
execution:
- executor: selenium
scenario: Demo-test
blazegrid: true
iterations: 1
capabilities:
browserName: chrome
scenarios:
Demo-test:
generate-flow-markers: true
headless: false
timeout: 10s
think-time: 0s
requests:
- label: Test
actions:
- maximizeWindow()
- go(http://blazedemo.com/index.php)
- selectByName(fromPort): "Boston"
- selectByName(toPort): "Rome"
- clickByCSS(input.btn.btn-primary)
- assertTextByCSS(h3): "Flights from Boston to Rome:"

If test data is defined in the YAML file, and you open the Test Data pane, the pane will be read-only, and it indicates that the test data is defined in the YAML file. You will not be able to use the Test Data pane to edit, rename, or delete test data within the BlazeMeter web UI, nor can you add parameters through the pane. The Data Settings and the Data Preview are similarly read-only, and there will be no option to change the data size there. Edit the size in the data dependencies section in the YAML file. To make changes to test data and settings, edit the YAML file directly.

In the above example, you see hard-coded data in the selectByName() and assertTextByCSS() commands, which you'd like to replace by parameters.

Create data-provider file

BlazeMeter allows usage of .csv files as data-providers for tests. For this scenario, create a "params.csv" file for the test shown in the Preconditions section:

fromPort,toPort
Paris,Buenos Aires
Philadelphia,Rome
Boston,London

The first row represents the names of parameters, the following rows are the values for the parameters. In this "params.csv" file, there are two data parameters and three rows of data.

Upload the file to BlazeMeter

After you've created a data-provider file, attach it to a test in BlazeMeter.

To upload the file, open the Test Configuration, switch the test to Script Mode, and click the blue plus button:

an uploaded CSV file

Refactor the test to use data from the file

Now that you have the data-provider file "params.csv" uploaded, refactor the test to use the file instead of hard-coded data in the test:

  1. Set the "iterations" parameter to 0, which means do as many iterations as there are rows of data in the file. For more information on iteration settings, see How to Load Test Data from Spreadsheets in Scriptless Tests.
    iterations: 0
  2. Link the scenario to the data-provider file as data source.
    data-sources:
    - params.csv
  3. Replace hard-coded values in test steps by Data Parameters:
          - selectByName(fromPort): ${fromPort}
    - selectByName(toPort): ${toPort}
    - clickByCSS(input.btn.btn-primary)
    - assertTextByCSS(h3): "Flights from ${fromPort} to ${toPort}:"

csv data source and data parameters in a yaml file

Run the test

Now you have parameterized the test to use data from the "params.csv" file. Since you have provided three rows of values in the file, the test is executed three times, each time with different data (1 iteration = 1 row of data).

Each iteration is executed in a separate session of the web driver:

sessions in the test report