krabhishek_30
7 years agoOccasional Contributor
Looping through test step multiple times until a condition is met
I have a use case where the API returns 202 the first time it is hit. After that, the end point should return 200 and should return some data.
It may happen that if the data is not ready in the subsequent hits the API could return 202.
What i want to do write a groovy to check if the status is 202, hit the API again, this condition is for 3 times. Even after 3 hits, the status is 202, fail the case.
Else if status is 200, do a set of operation.
This is the code that i have written.
String stat = testRunner.testCase.testSteps["<test step name>"].testRequest.response.responseHeaders["#status#"] testRunner.runTestStepByName("<test step name>") //run "<test step name>" step again as when run once, this step generates 202 and on subsequent hits, returns actual data. if( context.loopIndex == null ) context.loopIndex = 0 if( ++context.loopIndex < 3 && status == "202 Accepted") { testRunner.gotoStepByName( "<test step name>" )
log.info "Something...." } else if (status == "200 OK") { //do something here } else { //fail the case }
The problem i am facing is, after the first pass, the condition is not checked, code written after testRunner.gotoStepByName is executed and it exists after that.