jkrier
11 years agoRegular Contributor
How do I Loop test steps inside of a test suite?
I've read many different posts on loops but none of them seem to do exactly what I am looking for. I have a test suite with many different test steps. At some point I am trying a Groovy script to create a while condition that will run some previous test steps so many times and then continue on. I have tried the following different methods and they either loop continuously or they run the test step that I want but then return back to the script or it might iterate correctly the first run through but subsequent runs don't seem to hit the loop at all.
This method will loop continuously
def loop = 1
log.info loop
while (loop < 2){ //must match if loop
log.info "Still Running " + loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 2")
loop = loop + 1
}
This method will not loop at all but when I run it in the Groovy test step manually it says it's going to the correct steps in the correct order.
def loop = 1
log.info loop
while (loop < 2){ //must match if loop
log.info "Still Running " + loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 2")
loop = loop + 1
}
if (loop == 2){ //must match while loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 3")
loop = 0
log.info "ALL DONE "+loop
}
And this method i've tried running it a few different ways but the results are just like the above examples
if( context.loopIndex == null )
context.loopIndex = 0
log.info context.loopIndex
while( context.loopIndex < 2 ){ //number of times to run loop
//log.info context.loopIndex
testRunner.gotoStepByName( "getUniqueExternalReferenceValues 2" ) //name of step to go to
context.loopIndex = context.loopIndex + 1
log.info context.loopIndex
}if ( context.loopIndex == 2 ){
context.loopIndex = 0
log.info context.loopIndex
testRunner.runTestStepByName("getUniqueExternalReferenceValues 3")
log.info context.loopIndex
}
}
In case it is not clear this is what I want to accomplish
1. Run Test Step 1
2. Run Test Step 2
3. Run Test Step 3
4. Run Test Step 4
5. Run Test Step 5
6. Run Test Step 6
7. Hit Groovy loop (Begin Loop)
8. Run Test Step 5
9. Run Test Step 6
10. Hit Groovy Loop (End Loop)
11. Run Test Step 7
This method will loop continuously
def loop = 1
log.info loop
while (loop < 2){ //must match if loop
log.info "Still Running " + loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 2")
loop = loop + 1
}
This method will not loop at all but when I run it in the Groovy test step manually it says it's going to the correct steps in the correct order.
def loop = 1
log.info loop
while (loop < 2){ //must match if loop
log.info "Still Running " + loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 2")
loop = loop + 1
}
if (loop == 2){ //must match while loop
testRunner.gotoStepByName("getUniqueExternalReferenceValues 3")
loop = 0
log.info "ALL DONE "+loop
}
And this method i've tried running it a few different ways but the results are just like the above examples
if( context.loopIndex == null )
context.loopIndex = 0
log.info context.loopIndex
while( context.loopIndex < 2 ){ //number of times to run loop
//log.info context.loopIndex
testRunner.gotoStepByName( "getUniqueExternalReferenceValues 2" ) //name of step to go to
context.loopIndex = context.loopIndex + 1
log.info context.loopIndex
}if ( context.loopIndex == 2 ){
context.loopIndex = 0
log.info context.loopIndex
testRunner.runTestStepByName("getUniqueExternalReferenceValues 3")
log.info context.loopIndex
}
}
In case it is not clear this is what I want to accomplish
1. Run Test Step 1
2. Run Test Step 2
3. Run Test Step 3
4. Run Test Step 4
5. Run Test Step 5
6. Run Test Step 6
7. Hit Groovy loop (Begin Loop)
8. Run Test Step 5
9. Run Test Step 6
10. Hit Groovy Loop (End Loop)
11. Run Test Step 7