In GUI functional testing, sometimes you may want to parametrize 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 the following topics:
- Create data-provider file
- Upload file to Blazemeter
- Refactor test to use data from file
- Run test
Let's say we already have a simple test. The test will get 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:
- executor: selenium
- label: Test
- selectByName(fromPort): "Boston"
- selectByName(toPort): "Rome"
- 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:
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 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.
Now we have our test parametrized 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 separate session of web driver: