Forum Discussion

mu123's avatar
Occasional Contributor
2 years ago

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 multip...
  • ChrisAdams's avatar
    2 years ago



    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.