Forum Discussion
jkrier
11 years agoRegular Contributor
I figured out how to do this but it seems absurd that it must be done this way. You have to list out all of the steps between the loop and the start of the steps the loop is set to go back to. When you run this at the suite level it works fine, if you run this manually inside of the Groovy script step it loops continuously. The opposite of the behavior I noticed in one of my examples that, to me looks more appropriate than what actually ends up working. I also noticed that without the sleep some of the steps can step on each other.
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 700
testRunner.runTestStepByName("getTransitionPackages")
sleep 700
testRunner.runTestStepByName("TransitionProps")
sleep 700
testRunner.runTestStepByName("UpdateService_TransitionServiceItem")
sleep 700
testRunner.runTestStepByName("getSoaTransactionsByExternalAccountReference 3")
sleep 700
testRunner.runTestStepByName("checkTransitionStatus")
sleep 700
testRunner.runTestStepByName("TransitionVariables")
sleep 700
loop = loop + 1
}
if (loop == 2){ //must match while loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 3")
loop = 0
log.info "ALL DONE "+loop
}
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 700
testRunner.runTestStepByName("getTransitionPackages")
sleep 700
testRunner.runTestStepByName("TransitionProps")
sleep 700
testRunner.runTestStepByName("UpdateService_TransitionServiceItem")
sleep 700
testRunner.runTestStepByName("getSoaTransactionsByExternalAccountReference 3")
sleep 700
testRunner.runTestStepByName("checkTransitionStatus")
sleep 700
testRunner.runTestStepByName("TransitionVariables")
sleep 700
loop = loop + 1
}
if (loop == 2){ //must match while loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 3")
loop = 0
log.info "ALL DONE "+loop
}
- andresmjc7 years agoNew Contributor
This helped me out tremendously after searching through many posts. Did you ever get your issues resolved. My issue is that the script I wrote loops and calls itself. after it loops one time. it does go on to the next steps but the original script step fails.
- jkrier7 years agoRegular Contributor
This was a long time ago, I don't even remember why I needed this functionality anymore. I was messing with the script and it seems to be running without any issues.
def loop = 0 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("Step1") sleep 700 testRunner.runTestStepByName("Step2") sleep 700 loop = loop + 1 } log.info 'Loop End' testRunner.gotoStepByName("End Loop")
There might be a better way to accomplish this by using the step indexes. Get the current step (Groovy loop script) index and just run so many, you could add a counter and do something like testRunner.runTestStepByName("Step" + stepIndex)
Related Content
- 6 years ago
Recent Discussions
- 2 days ago
- 2 days ago