Looping over CSV file data and driving tests with Groovy
Whether it is for loading test data or writing reports, using external data files can be a key part of automated testing. Typically, you might need to read test data from a file and loop over some test steps until there is no more data. In this recipe, we see how this can be achieved easily using several reusable Groovy TestSteps
.
Getting ready
For example, let's say we have a small CSV file of invoice data that we want to use to drive our tests:
1,comp1,100.0,2014-12-01 00:00:00 2,comp2,200.0,2014-12-02 00:00:00 3,comp3,300.0,2014-12-03 00:00:00
You can find this data in <chapter2 samples>/invoice.csv
.
We will read each line and extract the values into properties, for example, to do something useful, for example, populating a web service request.
I have provided a completed SoapUI project GroovyFiles-soapui-project.xml
in the Chapter2
samples.
How to do it...
I'm going to break this down into three separate Groovy TestSteps...