Test data can be prepared in external sources for data-driven testing. These data sources can be:
- Excel Files
- CSV Files
- ODBC Sources
- SQL / ADO Objects
I will share an example of reading data from excel file for Sample Twitter Project available in SoapUI-Tutorials. Data in the Excel file is formatted as below:
To read data in groovy script, you need to import POI or JXL libraries.Since JXL does not support .xlsx format I am using Apache POI to read data from the excel file. Latest POI JAR files can download from http://poi.apache.org/download.html. Make sure to copy all the JAR files in the lib folder of SmartBear\SoapUI-5.3.0 before moving on!
The groovy script below can be added as first groovy script step in the test case of sample Twitter project. This script
- Reads data from excel file to determine if a test step should be executed or not.
- Determines and copies the test step name to be executed.
- Reads the data for property 'count' from excel file and uses it to set property value at test step level.
- Executes the test step with the modified count property value.
- Reads the test step property to verify that it was modified in step 3.
The output for above script should like below: