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:"
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
First row represents 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 file to Blazemeter
After we've created a data-provider file, let's upload it to test in Blazemeter.
Just upload the file for required test using Blazemeter interface:
Refactor 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).
- Link scenario with data-provider file.
- Replace hardcoded data by parameters.
Run test
Now we have our test parameterized by 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