How to execute same test step again until the condition is satisfied
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to execute same test step again until the condition is satisfied
I have a situation where I need to check a field in the API response. It changes after every 5 minutes, so need to trigger the API, check the response , if it has not reached the expected value, again check it after 5 minutes. Is there a way to do it? I tried it through data source loop, with property wait, but it stops the execution on the first failure and does not trigger the api again. Any help would be highly appreciated.
- Labels:
-
Data-Driven Testing
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@LK,
you can either use the Conditional Goto Test step or Groovy scripting.
There's a comprehensive article on controlling the test case flow using both these approaches in SoapUI/ReadyAPI docs.
Best regards,
Karel
https://apimate.eu
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Karel, thanks for your reply. I tried using groovy script and I am getting this error- groovy.lang.MissingPropertyException: No such property: java for class: Script4
error at line: 7
Scrpit:
import groovy.json.JsonSlurper
//def loopProperties = testRunner.runTestStepByName("REST Request")
//def count =Integer.parseInt (testRunner.testCase.testSuite.getPropertyValue( "availableEvStationCount" ))
def availableEvStationCount= testRunner.testCase.getPropertyValue( java.lang.string("availableEvStationCount") )
testRunner.testCase.setPropertyValue("availableEvStationCount", "availableEvStationCount" )
//Integer count = scount as Integer
if (availableEvStationCount<2)
{
Thread.sleep(5000)
} else {
testRunner.runTestStepByName("REST Request")
}
Could you please help.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@LK,
you can:
- call your API
- save the result into a property
- execute the Groovy script
See the screenshot below.
In the Groovy script, I would suggest utilizing testRunner.gotoStepByName( "RESTRequest"):
// The result is saved in a property value as string, transform into an integer
def result = Integer.parseInt(testRunner.testCase.getPropertyValue("result"))
if (result < 50) {
sleep(1000)
testRunner.gotoStepByName("RESTRequest")
}
If the result is 50 or higher, the loop is finished, and your test case continues.
Best regards,
Karel
https://apimate.eu
