Forum Discussion

jsreesoap's avatar
jsreesoap
Contributor
11 years ago

How to use sleep or delay in a loop

Hi
How do I make sure the test step is executed before it goes to next round of execution in executing test case in iterations?
In my test case I have 10 iterations to run 2 test steps. The second test step creates a unique value and writes to database. The code I am testing verifies the value that it creates and throws an exception if my script tries to creates the same value.

When I executed the test case some times it works but sometimes it fails since SoapUi is trying to run the test step without refreshing property values that are used as input.
For example ' "offerName":"ExemptOffer-K4018", here the offer name should be changed based on

Random r = new Random(System.currentTimeMillis());

String number = "";
for(int j=0; j < 4; j++) {
number +=Integer.toString(r.nextInt(9));

}
def exmType = context.expand( '${#TestSuite#ExmType}' )

testRunner.testCase.testSuite.setPropertyValue("offerName", "ExemptOffer-" + exmType +number)

log.info "number" + number
script. I see the number is changing in log but not in my script.
How do I put a check to make sure it goes to next iteration only when the running iteration is done?
Thanks
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    You can use
    Thread.sleep(n) //n in milliseconds 
    to put a delay in your script.
    If that is not what you are looking for, please share the flow of your TestCase because it is not clear what you mean by "your script" versus the code you have posted and how it all relates together.

    Thanks,

    Giscard
    SmartBear Support
  • I am trying to use sleep to check on the completion of execution of a test step. For example if I have 4 test steps and 3rd one takes more time than the others I want to make sure that execution wont jump to test step 4 when 3rd one is still running.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    When you run your TestCase, the execution of TestStep 4 won't start until TestStep 3 has finished.
    It will be sequential.

    Regards,

    Giscard
    SmartBear Support