Ask a Question

Verify multiple rows and then data drive

Frequent Contributor

Verify multiple rows and then data drive

First off I am new to Soup/ReadyAPI. 

I have an API that returns row information for a grid.

I have assertions for the count of rows and the first row. I am also verifying the data against an excel sheet which is all working fine.


The problems comes when I add more than one row of data in the excel sheet as i want to validate multiple rows. I cannot get this to work. Ideally I want to validate 3 rows on each run looking at the same excel sheet.

Any ideas how I do this? Eventually I want to datadrive this as well.


Screenshots of assertions and data returned plus excel sheet.



Community Hero

Full project to be found here

If my answer helped please click on the 'Accept as Solution' button.
Frequent Contributor

It looks like I was trying to overcomplicate it and heading the wrong way.

Thnk you so much. I will have  study of your solution and ifyou dont mind ask anythign that is not clear as I want to ensure I properly understand what you have done.


Thanks again

Sure, just let me know if you run into more trouble.

If my answer helped please click on the 'Accept as Solution' button.
Frequent Contributor


I have had a good look and can make sense of what you have done. Thank ou as its a very simple way to resolve the problem I was having.

However if I put the incorrect information in the spreadsheet it passes even though the data does not match.

I have 3 rows in my excel. The first two should match and pass. The 3rd row has a valid ID but the data does not match between the response and the excel row. It says it has passed though?

Frequent Contributor

Also just to add if I leave this line as it is, it fails every time as in the screenshot I have attached. Even if the data matches.

if (jsonObject.value[i].Id ==id)






I don't have time to look into it today but you can try to do it by introducing some logs. You can log stuff with the command "stuff" ).

If my answer helped please click on the 'Accept as Solution' button.
Frequent Contributor

I think after having a look that 'jsonObject.value' does not exist after jsonSlurper has parsed the text.

If I do ' jsonObject;' the log does not show values for each node.


Maybe this is why? If so I am not sure how to get around this but will keep digging

Frequent Contributor

I have spent a good amount of time looking at this yesterday and today but I cannot get the code to work.

I dont think there is just one issue.


I think the issue is the loop at the bottom. 'i' is being set at 48 on the first run.


Screenshot of me running it. On the first loop through it is setting 'i' to 48. I prove this by logging the testID response and this is the test ID of my 48th row.


Any ideas would be greatly appreciated.








Can you place again the materials with which you are working? I will try to help you further.


If my answer helped please click on the 'Accept as Solution' button.
Frequent Contributor

'i' always seems to start at 48. Below is code and also attached the spreadsheet and the jsonObject log.

If you need anything else please let me know




import groovy.json.JsonSlurper

// Get the id from the datasource
def id = context.expand( '${DataSource#ID}' )

// Get the response from the GetResponse step
def response = context.expand( '${TestRequest#Response}' )

// Parse the response with JsonSlurper
def jsonSlurper = new JsonSlurper()
def jsonObject = jsonSlurper.parseText(response)

// Get the element where the ID is the same as in the datasource
for (int i = 0; i < jsonObject.value.size(); i++) {
    if (jsonObject.value[i].Id ==id) {
        // Start comparison

        assert jsonObject.value[i].TestID.equals (context.expand( '${DataSource#TestID}' ))
        assert jsonObject.value[i].TestName.equals( context.expand('${DataSource#TestName}'))
        assert jsonObject.value[i].Assays.equals( context.expand('${DataSource#Assay}'))
        assert jsonObject.value[i].Analyses.equals( context.expand('${DataSource#Analyses}'))
        assert jsonObject.value[i].Cassettes.equals( context.expand('${DataSource#Cassettes}'))
        assert jsonObject.value[i].Enabled == context.expand('${DataSource#Enabled}').toBoolean()
        assert jsonObject.value[i].UserDefined == context.expand('${DataSource#UserDefined}').toBoolean()





Showing results for 
Search instead for 
Did you mean: