Forum Discussion

bpistole's avatar
bpistole
Contributor
7 years ago

how to Iterate through multiple records in a single reponse.

I have an API that will return x number of records.   For instance it may return all book written by author x.

The response will contain the number of books returned, such as 4 book written by author x.

I want to be able to validate the same elements, such as publisher, for each book record returned.

 

psudo code:

Get all book written by X.

-> 4 books returned.

Loop throw return response for each book

- Check book 1 was published by Z

- Check book 1 was published by Y

- Check book 1 was published by X

- Check book 1 was published by W

 

I've written a script to do this but is there another way to handle this sort of situation that is faster than written it for each call?

 

I'm using SoapUI Pro with ready API 

 

Thanks,

Billy

3 Replies

  • Admin, I reposted this in SoapUI Pro since that is the version I am using.  Please delete this post.

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      Unfortunately it sounds like a groovy script assertion is your best bet. I can't think of a better way.

  • PaulMS's avatar
    PaulMS
    Super Contributor

    Maybe use an xpath or jsonpath match assertion like 

     

    $..publisher

     

    Expected result

    [Z, Y, X, W]