Forum Discussion

eeyoreeco's avatar
eeyoreeco
Occasional Contributor
11 years ago

DataSource using Groovy Script

Hi Friends, Good day!

I would like to ask some help regarding using the 'Groovy Script' as my data source (since this [Datasource] functionality is not available for non-pro SoapUI).

SCENARIO:
I have this data from my excel sheet.
___________________________________
| A | B |
___________________________________
1 |From Currency | To Currency |
----------------------------------------
2 |USD | AUD |
----------------------------------------
3 |USD | USD |
----------------------------------------
4 | InvalidData | GBP |
----------------------------------------

In a Test Case I have 3 Test Step. per test step I need to retrieve the data from the
excel file (see table). How I will be able to retrieve this data and use it as my data in my
parameters ("From Currency" & "To Currency"). Thanks

MY SAMPLE Pseudocode:
1.) Open Excel
2.) Retrieve Data (Column/Row)
3.) Store the Retrieve Data from a variable. Tocurrency[2] & Fromcurrnecy[2] (via iteration)
4.) 1st Test Step use the Fromcurrency[0] & Tocurrnecy[0] (USD to AUD)
5.) 2nd Test Step use the Fromcurrency[1] & Tocurrnecy[1] (USD to USD)
6.) 3rd Test Step use the Fromcurrency[2] & Tocurrnecy[2] (InvalidData to GBP)

Sample Request: 1st Test step

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>Fromcurrnecy[0]</web:FromCurrency>
<web:ToCurrency>Tocurrency[0]</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>


How I will be able to code this one using a Groovy Script ? Any help will be greatly appreciated! Thanks

1 Reply

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Excel files will be more of a pain, I typically use either a database (SQLite3 or Access) or a CSV file.

    As for doing what you are attempting to do:

      1) Have groovy read the Database/CSV file

      2) Store the data to a property

      3) Store the row of the data to a property

      4) Have the teardown script check if there is another row, if so go ahead and use it


    There is a great article for how to perform these steps here:

    A Simple Data-Driven Testing Technique