Forum Discussion
aaronpliu
5 years agoFrequent Contributor
Hi 4nes-team ,
one loop can resolve your question. But I did not see a complete JSON response, assume that you get a response with a list. Run your test case
/**
* TEST CASE
* REST STEP
* GROOVY STEP
*/
import groovy.json.JsonSlurper
def teststep = testRunner.testCase.testSteps['REST STEP']
// get REST response
def response = teststep.testRequest.response.contentAsString // context.expand( '${REST STEP#Response}' )
def json = new JsonSlurper().parseText(response)
// assume you get a list named "MyNode"
if (json.MyNode.any {it.reasonCode == 'EM_004}) {
testRunner.gotoStepByName("Next Step")
} else {
Thread.sleep(1000) // set your delay time
testRunner.gotoStepByName("REST STEP")
}
Thanks,
/Aaron
4nes-team
5 years agoOccasional Contributor
Hi Aaron,
thank you for your quick reply.
I tried to implement your code into my testcase but apparently I'm doing something wrong. Could you take a look? You can see the error in the screenshot I attached.
Thanks again.
4nes team