doubtsreadyapi
5 years agoContributor
Groovy script for Assertion to check value
Hi I am trying to write a script assertion, where in response after a particular "id" i have to check the status of other property, Below is my sample response { "gr" : [ { "args" : [ ...
- 5 years ago
Thanks for the Update.
I tried modifying the Code like below, its working now.. Before i was facing error. it was failing in some environments
import groovy.json.JsonSlurper def response = messageExchange.response.responseContent def jsonsl = new JsonSlurper().parseText(response) def Result = jsonsl.gr[0].args def count = Result.size() def flag = false for (int i=0;i < count; i++){ if (Result[i].Id == "abcd"){ for (int j=i ; j < count; j++){ def id = Result[j].Id if(id == "d1234"){ def status = Result[j].State assert id == "d1234" : "d1234 not found" assert status == 'success' : "d1234 failed" flag = true; } } } } assert flag , "d1234 is missing"
Thanks