Prathyusha
Prathyusha

Reputation: 123

Get a parent value based on child value in SoapUI

In the response Json, getting an array list of items as shown.

Upvotes: 0

Views: 172

Answers (1)

Rao
Rao

Reputation: 21389

What you see in the question is not xml, it is a json string. So, xpath does not work.

For your request test step, you can add the Script Assertion as shown below:

//Check the response
assert context.response, 'Response is empty or null'

//Expected subscription id, change it if needed
def expectedSubscriptionId = '2c92c0f95ae1445b015af2320235689f'

def parsedJson = new groovy.json.JsonSlurper().parseText(json)
def ids = [] as Set
parsedJson.each { item ->
   item.amendments.each { amendment ->
      if (amendment.subscriptionId == expectedSubscriptionId ) {
         ids << item.id
      }
   }
}


assert ids.size(), "id's are not found in the response for matching subscription"
log.info "Matching id's are : ${ids}"

You may quickly try online Demo

Upvotes: 1

Related Questions