Solved
Forum Discussion
nmrao
5 years agoCommunity Hero
Have a look at the script, hope it helps. follow the comments in the script.
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/AccessResponseData.groovy
rajs2020
5 years agoFrequent Contributor
nmrao - Thanks, I saw your solution also now. It works, but I have some questions.
1 - Why do you use closures here instead of regular functions?
2 - How do we reuse the code in other suites also instead of repeating the code?
PS - I modified your solution as follows.
/*
Sample response:
Content-Type: application/json; charset=utf-8
{"healthy": true}
*/
//The test step which calls the API.
def stepName = 'CallApi'
assert getHeader(stepName, 'Content-Type') == 'application/json; charset=utf-8'
assert getJson(stepName).healthy == true
//Utility functions:
def getStepResponse(stepName){
context.testCase.testSteps[stepName].httpRequest.response
}
def getJson(stepName){
new groovy.json.JsonSlurper().parseText(getStepResponse(stepName).responseContent)
}
def getHeader(stepName, header){
getStepResponse(stepName).responseHeaders[header].first()
}