Forum Discussion
I had to tidy up your JSON for it to properly be parsed by SoapUI.
{ "id": "XYZ", "errordetails": null, "statuscode": 200, "message": null, "data": [ { "key1": 1294, "key2": [ { "sub-key1": 0, "sub-key2": 2360 }, { "sub-key3": 0, "sub-key4": 2820 } ], "key3": true, "key4": "3X2" }, { "Key1": 1294, "key2": [ { "sub-key1": 0, "sub-key2": 2360 }, { "sub-key3": 0, "sub-key4": 2820 } ], "key3": true, "key4": "3X2" } ] }
Here's my solution using a script assertion. It's probably a very round-about way of doing it. But it works.
def expected = [
"key1",
"key2",
"key2/sub-key1",
"key2/sub-key2",
"key2/sub-key3",
"key2/sub-key4",
"key3",
"key4"
]
def holder = new com.eviware.soapui.support.XmlHolder(messageExchange.responseContentAsXml)
def exists = { it -> holder["count(//*:data//*:${it.replace("/", "//*:")})"].toString().toInteger() > 0 }
expected.each {key -> assert exists(key) }
Hello team,
I was able to look at the sample code suggestion and i worked on my solution .
However i get the script popup window which gives all the keys but not assertion passed message. How do i work it out into
this current script
// Get API response
def Response = context.expand( '${Validate Testcasename#Response}' )
log.info(Response)
def slurp = new groovy.json.JsonSlurper().parseText(Response)
//verify the slurper isn't empty
assert !(slurp.isEmpty())
//Capture expected keys to match API reponse keys
def expected =
[
"key1",
"key2",
"key2/sub-key1",
"key2/sub-key2",
"key2/sub-key3",
"key2/sub-key4",
"key3",
"key4"
]
def exists = { it -> slurp["count(//*:data//*:${it.replace("/", "//*:")})"].toString()}
expected.each {key -> assert exists(key) }
Related Content
- 3 years ago
- 2 months ago
Recent Discussions
- 11 days ago