How to run specified step in SoapUI according testcase result

左心房为你撑大大i 提交于 2019-12-11 03:09:11

问题


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:

  1. request step1
  2. request step2
  3. groovy script step (the proposed script to handle the scenario)
  4. request1 step if above step1 & step2 are successful
  5. request2 step otherwise
  6. following step x
  7. 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 use gotoStepByName 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!