问题
I have project in soapui with more testcases. After running each testcase I need to run one of two http request, depending on results of steps. So if one or more steps in testcase failed, I need to run httprequest1 and if all steps passed I need to run httprequest2. How can I do this? I have tried many scripts... for now my best solution is something like this, just add groovy script at the end of test case. Problem is that it is checking only last step. I have tried many other solutions, but nothing was working for me. Can somebody help me with this? Thank you
def lastResult = testRunner.getResults().last()
def lastResultStatus = lastResult.getStatus().toString()
log.info 'Test + lastResultStatus
if( lastResultStatus == 'FAILED' )
{
testRunner.gotoStepByName( 'httprequest1' )
testRunner.testCase.testSteps["httprequest2"].setDisabled(true)
}
else
{
testRunner.gotoStepByName( 'httprequest2' )
}
another solution that I have tried:
for( r in testRunner.results )
result = r.status.toString()
log.info result
if( result == 'FAILED' )
{
testRunner.gotoStepByName( 'httprequest1' )
testRunner.testCase.testSteps["httprequest2"].setDisabled(true)
}
else
{
testRunner.gotoStepByName( 'httprequest2' )
}
回答1:
Like it was mentioned in the comment, and based on the details shared in the comments, Conditional GoTo
test step can be used. However, it may required multiple of them. Instead Groovy Script
can be the best way in this scenario.
Here are the details assuming the following are the steps in the test case.
Test Case:
- request step1
- request step2
- groovy script step (the proposed script to handle the scenario)
- request1 step if above step1 & step2 are successful
- request2 step otherwise
- following step x
- following step y
Here is the pseudo code for the proposed Groovy Script
mentioned in #3.
- Evaluate the previous test step execution result, like what you currently doing.
- Based on the condition, run the test step #4 if true, run step #5 otherwise. Here note that do not use
gotoStepByName
method, instead run step by its name. See sample #15 here - Once the above
if
..else
is done, then usegotoStepByName
to continue the steps #6, #7 (of course, if any).
NOTE: If gotoStepByName
is used to run a step in groovy step, then the control will not come back.
回答2:
Use a testcase teardown to call the step, since you have to do it for all test cases. The teardown script will look something like this:
if(testRunner.status.toString() == "FAILED"){
testRunner.runTestStepByName( "httprequest1")
println "in if"
}else{
testRunner.runTestStepByName( "httprequest2")
println "in else"
}
Note that you have to use the SoapUI Runner to trigger the testcase / suite and the difference in method being called.
来源:https://stackoverflow.com/questions/39856956/how-to-run-specified-step-in-soapui-according-testcase-result