jsreesoap
12 years agoContributor
How to stop execution when it gets out of loop
// run ten random requests
for( i in 1..10 )
{
if( Math.random() > 0.5 )
testRunner.runTestStepByName( "Request 1")
else
testRunner.runTestStepByName( "Request 2")
}
// do something else
would run ten random requests before executing the remaining script.
The above I picked it up from Controlling Flow .....
Here it says it would run ten random requests before executing the remaining script. How do I stop executing the remaining script once the loop is done. I tried break but it still runs once after completing the loop.
My Script:
def int j
import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
for (y in 0..2){
if (y==0){testRunner.testCase.testSuite.setPropertyValue("ExmType","A")}
sleep 300
if (y==1){testRunner.testCase.testSuite.setPropertyValue("ExmType","B")}
sleep 300
if (y==2){testRunner.testCase.testSuite.setPropertyValue("ExmType",C")}
sleep 300
j=0
sleep 600
for(x in j..2){
log.info "x"+x
log.info "j" + j
if (x==0){testRunner.testCase.testSuite.setPropertyValue("exeType", "A")
testRunner.testCase.testSuite.setPropertyValue("AccType", "Q")}
sleep 300
if (x==1){testRunner.testCase.testSuite.setPropertyValue("AccType", "S")}
sleep 300
if (x==2){testRunner.testCase.testSuite.setPropertyValue("AccType", D")}
testRunner.runTestStepByName("DataGen")
testRunner.runTestStepByName("ClosingDate groovy")
testRunner.runTestStepByName("Groovy Script")
testRunner.runTestStepByName( "Authheader to Create a Private Placement-test")
def httpResponseHeadersAuth = context.testCase.testSteps["Authheader to Create a Private Placement-test"].testRequest.response.responseHeaders
def httpStatusAuth = httpResponseHeadersAuth["#status#"]
def httpStatusCodeAuth = (httpStatusAuth =~ "[1-5]\\d\\d")[0]
testRunner.runTestStepByName( "PropertyTransfer 1")
testRunner.runTestStepByName( "Create Private Placement-test")
def httpResponseHeaders = context.testCase.testSteps["Create Private Placement-test"].testRequest.response.responseHeaders
def httpStatus = httpResponseHeaders["#status#"]
def httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]
log.info("HTTP status code: " + httpStatusCode)
if (y==2 && x==2 && httpStatusCode==201){exit}
}
}
I want it to run only 9 times but after exiting the loop it runs one more time. How do I stop the execution once it gets out of loop?
The test case structure is in screenshot.
Thanks in advance
for( i in 1..10 )
{
if( Math.random() > 0.5 )
testRunner.runTestStepByName( "Request 1")
else
testRunner.runTestStepByName( "Request 2")
}
// do something else
would run ten random requests before executing the remaining script.
The above I picked it up from Controlling Flow .....
Here it says it would run ten random requests before executing the remaining script. How do I stop executing the remaining script once the loop is done. I tried break but it still runs once after completing the loop.
My Script:
def int j
import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
for (y in 0..2){
if (y==0){testRunner.testCase.testSuite.setPropertyValue("ExmType","A")}
sleep 300
if (y==1){testRunner.testCase.testSuite.setPropertyValue("ExmType","B")}
sleep 300
if (y==2){testRunner.testCase.testSuite.setPropertyValue("ExmType",C")}
sleep 300
j=0
sleep 600
for(x in j..2){
log.info "x"+x
log.info "j" + j
if (x==0){testRunner.testCase.testSuite.setPropertyValue("exeType", "A")
testRunner.testCase.testSuite.setPropertyValue("AccType", "Q")}
sleep 300
if (x==1){testRunner.testCase.testSuite.setPropertyValue("AccType", "S")}
sleep 300
if (x==2){testRunner.testCase.testSuite.setPropertyValue("AccType", D")}
testRunner.runTestStepByName("DataGen")
testRunner.runTestStepByName("ClosingDate groovy")
testRunner.runTestStepByName("Groovy Script")
testRunner.runTestStepByName( "Authheader to Create a Private Placement-test")
def httpResponseHeadersAuth = context.testCase.testSteps["Authheader to Create a Private Placement-test"].testRequest.response.responseHeaders
def httpStatusAuth = httpResponseHeadersAuth["#status#"]
def httpStatusCodeAuth = (httpStatusAuth =~ "[1-5]\\d\\d")[0]
testRunner.runTestStepByName( "PropertyTransfer 1")
testRunner.runTestStepByName( "Create Private Placement-test")
def httpResponseHeaders = context.testCase.testSteps["Create Private Placement-test"].testRequest.response.responseHeaders
def httpStatus = httpResponseHeaders["#status#"]
def httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]
log.info("HTTP status code: " + httpStatusCode)
if (y==2 && x==2 && httpStatusCode==201){exit}
}
}
I want it to run only 9 times but after exiting the loop it runs one more time. How do I stop the execution once it gets out of loop?
The test case structure is in screenshot.
Thanks in advance