In GUI functional testing, sometimes you may want to parameterize your test to use external data instead values hardcoded 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:
- Precondition
- Create data-provider file
- Upload file to BlazeMeter
- Refactor test to use data from file
- Run test
Precondition
Let's say we already have a simple test as a YAML file. The test will go to the http://blazedemo.com site, then select values in two dropdowns, submit the selection and, finally, will assert 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 displays the message "Test data is defined in YAML" for your information. 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, we can see hardcoded data in selectByName() and assertTextByCSS() commands, which we'd like to replace by parameters.
Create data-provider file
BlazeMeter allows usage of .csv files as data-providers for test. Let's create a "params.csv" file for our test from precondition section:
fromPort,toPort
Paris,Buenos Aires
Philadelphia,Rome
Boston,London
The first row represents the names for our parameters, all the following rows are the values for the parameters. So in our "params.csv" file we have 3 rows of data.
Upload the file to BlazeMeter
After we've created a data-provider file, let's attach it to a test in BlazeMeter.
To upload the file, open the Test Configuration and click the blue plus button:
Refactor the test to use data from file
Now that we have the data-provider file "params.csv" uploaded, let's refactor the test to use our file instead hardcoded data in test:
- Set "iterations" parameter to 0 (which means do as many iterations as many rows of data we have in our file). For more information on iteration settings, see How to Load Test Data from Spreadsheets in Scriptless Tests.
iterations: 0
- Link the scenario with data-provider file.
data-sources:
- params.csv - Replace hardcoded values by parameters:
- selectByName(fromPort): ${fromPort}
- selectByName(toPort): ${toPort}
- clickByCSS(input.btn.btn-primary)
- assertTextByCSS(h3): "Flights from ${fromPort} to ${toPort}:"
Run the test
Now we have our test parameterized to use data from the "params.csv" file. Since we have 3 rows of values in the file, our test will be executed 3 times, each time with different data (1 iteration = 1 row of data).
Each iteration will be executed in a separate session of the web driver:
0 Comments