Ask a Question

How to iterate throw Excel data in a groovy script?

Taz
Contributor

How to iterate throw Excel data in a groovy script?

I created a data source with Excel and want to use it in a groovy script.  Using "Get Data" I can get individual properties but it appears to only pick out individual data properties from the last row.  I would like to get the whole sheet as an object, either of rows and columns or a list of objects.  How can this be best achieved?

4 REPLIES 4
nmrao
Champion Level 3

If you are using data driven tests, it is possible to iterate the data source records without scripting. Please see the following documentation

https://support.smartbear.com/readyapi/docs/testing/data-driven/concepts.html

https://support.smartbear.com/readyapi/docs/testing/data-driven/index.html

 

Video here

https://www.youtube.com/watch?v=AFtyMUiD-5s

 

Here another resource if you wanted only groovy way:

https://www.evoketechnologies.com/data-driven-testing-using-soap-ui-groovy/



Regards,
Rao.
Data-driven testing is useful when you want to vary contents of your API requests. Learn how to use Excel files as data sources and how to save test run data to Excel files. Try ReadyAPI for free today: https://smartbear.com/product/ready-api/free-trial/ Helpful links: * REST testing playlist: ...

Thank you for the reply.  I was aware of the data-driven concepts but they didn´t address the issue of me wanting to use the Excel Data within a groovy script.  From your answer I guess the only way is to use a third party component like SoapUI.  I will look into this.  

nmrao
Champion Level 3

One can use groovy in ReadyAPI. Note that SoapUI is also from Smartbear, but free.



Regards,
Rao.
SarahS
Staff

Hi @Taz,

Understanding that your goal here is to use the entire data set in a script. One approach I can think of would be to read in each row of data and perhaps pass this into an array. The syntax for referencing a row is as follows:
${DataSouceTestStep#DataSourceProperty::RowNumber}

You can use a property/variable as the RowNumber to iterate through the data set.

Documentation for this is here if you want to get more details.
https://support.smartbear.com/readyapi/docs/functional/steps/data-source.html

cancel
Showing results for 
Search instead for 
Did you mean: