Iterating through Data source values and verifying the matched value
This is the scenario that I am trying to test:
1. I have a REST API step that returns number of ids and names for locations. (Sometimes zero records are returned, sometimes one and sometimes multiple records are returned)
2. I have to write a test to iterate through the REST Response and verify the location name and get the corresponding id.
I tried to test this by
1. Creating a Data source from the Json response of the REST API step. 11 rows of id and name were returned.
2. I am trying to write a groovy script to iterate through all the rows of Data source but couldn't do it.
I can only get the last row in the groovy script. Please let me know how to test this scenario.
Solved! Go to Solution.
Can you post the groovy script you've done so far please?
Also people are going go need the payload content for jsonpath to help wirh your script.
I'm assuming you have the licensed version of ReadyAPI if you're using a Datasource step. If you are, do you have a data source loop with the groovy script in between?
Or, if unlicensed, we'd need to see what you've put together this far as @richie suggests.
You're over-thinking this. The solution is much easier and you're not far off.
Data-driven tests that use a Datasource step need a Datasource Loop step. This handles the iteration of the data set. Steps in between the Datasource and Datasource Loop are called for each row in the data source.
Using your screen shot as a guide, here's what I think you should be moving towards....
Note the Data Source Loop step and how Ready API indicates the loop with the arrow.
When you add the Data Source Loop step, you have to configure it. Here's how I did mine for your example...
The first value is the link to the data source of interest. The second value is the first step inside the loop that you want to call.
Before moving onto the Groovy step, it's worth looking at the Datasource. Again, I borrow from your example...
These properties are accessible within the loop and contains the values for the current row in the datasource. Without the loop step, you always get the last row.
Ok, Groovy script and how to access the current values....
Here is the content of the "Let's log stuff - Groovy script' step.
You can type all this in, but now is a good opportunity to mention "Get Data". In your Groovy Step, if you right-click, there is an option called Get Data. If you click this, you can navigate to the Datasource step and select the value of interest without typing.
You'll notice I added an additional step call "REST Request to call in each iteration". You can apply the same Get Data idea. If you want to call another service for each id in your datasource, then instead of calling with a hard-coded value, again right click where the param needs to use get data. E.g.
I tried modifying the groovy script. But every time it references only the last row of the data source. Any help would be appreciated.
Can you share the Groovy script?
As @ChrisAdams said - can you please publish the groovy script? I know you did attach a word doc which included the groovy script - but it doesn't render correctly and I can't read the groovy properly.
I changed the start row to null, end row to null, and Rows per iteration to null. Now the script works.
Thank you all for the suggestions.