Forum Discussion

jkrier's avatar
jkrier
Regular Contributor
10 years ago

[RES]Groovy step is treated differently when ran from suite

I am trying to loop a set of test steps for a specific amount of runs in the middle of a test suite. I have written a Groovy script to do this. If I disable the Groovy loop script and then run my suite up to the Groovy loop step and then manually run the Groovy step from inside of the Groovy step it works; the previous steps run the exact amount of times I wish them to. When the Groovy script is enabled and I run from the suite the suite will loop the steps in the Groovy script infinitely.

Is there a reason that this happens?


Here is my Groovy script.

def loop = 1
log.info loop
while (loop < 2){ //must match if loop
log.info "Still Running " + loop
//You have to explicitly list all steps to run between the loop script and the test step loop start
testRunner.runTestStepByName("getUniqueExternalReferenceValues 2")
sleep 1000
testRunner.runTestStepByName("getTransitionPackages")
sleep 1000
testRunner.runTestStepByName("TransitionProps")
sleep 1000
testRunner.runTestStepByName("UpdateService_TransitionServiceItem")
sleep 1000
testRunner.runTestStepByName("getSoaTransactionsByExternalAccountReference 3")
sleep 1000
testRunner.runTestStepByName("checkTransitionStatus")
sleep 1000
testRunner.runTestStepByName("TransitionVariables")
sleep 10000
loop = loop + 1
}

if (loop == 2){ //must match while loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 3")
loop = 0
log.info "ALL DONE "+loop
}


I know that you do not support custom scripts but what I think is incorrect is that it's treated differently depending on how it's ran plus technically I believe my script should work. It is correct code to do what I want and the soapUI client is ignoring what the script is telling it to do. If I run this script in a Groovy console and remove the test steps the loop works just fine. For example, if you comment out all of the soapUI test steps and run the script in a Groovy console the output is as expected.

def loop = 1
println loop
while (loop < 5){ //must match if loop
println "Still Running " + loop
//You have to explicitly list all steps to run between the loop script and the test step loop start
/*testRunner.runTestStepByName("getUniqueExternalReferenceValues 2")
sleep 1000
testRunner.runTestStepByName("getTransitionPackages")
sleep 1000
testRunner.runTestStepByName("TransitionProps")
sleep 1000
testRunner.runTestStepByName("UpdateService_TransitionServiceItem")
sleep 1000
testRunner.runTestStepByName("getSoaTransactionsByExternalAccountReference 3")
sleep 1000
testRunner.runTestStepByName("checkTransitionStatus")
sleep 1000
testRunner.runTestStepByName("TransitionVariables")
sleep 10000*/
loop = loop + 1
}

if (loop == 5){ //must match while loop
//testRunner.gotoStepByName("getUniqueExternalReferenceValues 3")
loop = 0
println "ALL DONE "+loop
}

groovy> def loop = 1
groovy> println loop
groovy> while (loop < 5){ //must match if loop
groovy> println "Still Running " + loop
groovy> //You have to explicitly list all steps to run between the loop script and the test step loop start
groovy> /*testRunner.runTestStepByName("getUniqueExternalReferenceValues 2")
groovy> sleep 1000
groovy> testRunner.runTestStepByName("getTransitionPackages")
groovy> sleep 1000
groovy> testRunner.runTestStepByName("TransitionProps")
groovy> sleep 1000
groovy> testRunner.runTestStepByName("UpdateService_TransitionServiceItem")
groovy> sleep 1000
groovy> testRunner.runTestStepByName("getSoaTransactionsByExternalAccountReference 3")
groovy> sleep 1000
groovy> testRunner.runTestStepByName("checkTransitionStatus")
groovy> sleep 1000
groovy> testRunner.runTestStepByName("TransitionVariables")
groovy> sleep 10000*/
groovy> loop = loop + 1
groovy> }
groovy> if (loop == 5){ //must match while loop
groovy> //testRunner.gotoStepByName("getUniqueExternalReferenceValues 3")
groovy> loop = 0
groovy> println "ALL DONE "+loop
groovy> }

1
Still Running 1
Still Running 2
Still Running 3
Still Running 4
ALL DONE 0

14 Replies

  • jkrier's avatar
    jkrier
    Regular Contributor
    Hello Marcus, I am unfamiliar with using event handlers. Do you mean create 2 new Groovy steps and put one in front and one after the CheckTransitionStatus? Also, can you provide an example of how they are used?

    I did remove the getSoaTransactions 2 and the CheckTransitionStatus and added a 10 second delay instead (Just guess it would be enough time for the transaction to complete) and this does seem to solve the issue so it does look like there is a problem with running a Groovy step inside the while loop but this extra Groovy step would not be running inifinitely, it might need to run 10 times or something but it will eventually error or finish plus that is not where it runs continuously, rather the entire while loop is what runs continuously. So all of the steps listed in my Groovy loop code is what is executed over and over.

    I don't think I can provide this project as it's too proprietary. I can try and strip out the calls to GoogleAPI and loop them. It would basically be the same thing. Would that be OK?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    I don't think I can provide this project as it's too proprietary. I can try and strip out the calls to GoogleAPI and loop them. It would basically be the same thing. Would that be OK?



    Yes, that would be OK I suppose.


    Hello Marcus, I am unfamiliar with using event handlers. Do you mean create 2 new Groovy steps and put one in front and one after the CheckTransitionStatus? Also, can you provide an example of how they are used?


    Apologies, I should have provided you with the link below for more information on event handlers.

    http://www.soapui.org/Scripting-Propert ... dlers.html

    Also, depending on what that Groovy step "CheckTransitionStatus" is doing that could be a problem. If it is running multiple times it could cause a "hanging" affect observed in the GUI or it could be just taking a long time to finish. I would also suggest you try running your test case using <SoapUI Pro install>\bin\testrunner.bat\.sh from command line to see if you observe the same thing.

    http://www.soapui.org/Test-Automation/c ... tests.html

    Regards,
    Marcus
    SmartBear Support
  • jkrier's avatar
    jkrier
    Regular Contributor
    Sorry for not getting back with you sooner. The project I created this script for is over and I worked around it by adding in Delay steps instead of finding out the actual values I needed by calling the status requests until the desired status was returned. This is still an issue I believe but I no longer have time to work on it due to other testing that I am doing now. I tried to create a project by calling some other public API's (Flickr, Amazon, Google) but none of those provide a request where a value will change in the response after some time, at least this would not be something I could do quickly without learning how their services work in more detail. Unfortunately I do not have time to do that.
  • jkrier's avatar
    jkrier
    Regular Contributor
    I forgot to thank you for your help. Thank you!