Forum Discussion

Postavshik's avatar
Postavshik
New Contributor
8 years ago

How to abort test case in SoapUI ONLY if all two assertions failed? Some groovy script?

I have very simple test case.

I send request to service, this request in loop. And I need to make this loop until catch bad response. I have two assertions which have to FAIL and only then stop test case execution. If fail only one of them - continue execution in loop.

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    How are you running the test in a loop? a data driven or a thru a groovy script? what is the structure of the test case? If you already using a script, please post it. What kind of kind assertion do you have currently?
    • Postavshik's avatar
      Postavshik
      New Contributor

      Hi.

       

      I run a test in a loop with help of Groovy script.

      Here is simple script

      if( context.loopIndex == null )
         context.loopIndex = 0
      
      if( ++context.loopIndex < 10 )
         testRunner.gotoStepByName( "Name of first TestStep in loop" )

       

      Testcase has to steps:

      1. SOAP request

      2. Groovy script which loop step 1

       

      I have two assertions

      1. Contains text - Error 20. If text IS presented than it s VAILD

      2. Xpath - if the value of the nod presented than it s VAILD

       

      During making request sometimes service give me another wrong response, which I don't need to catch. When I receive "Error 20" I want to ignore that response and continue looping my request until I catch assertion number 2.

      Problem is, that when service returns "Error 20", assertion 2 fails. because server return completely wrong response. That's why I wanted to create conditions like that test case stopped only if both assertions failed, not only one of them.

       

      OR

       

      If you can recommend how to create conditions with one assertion, but which will have something like "If I see Error 20 response, ignore it and continue loop until assertion 2 failed"

       

      • Radford's avatar
        Radford
        Super Contributor

        While you could use Groovy I personally always like to see if the base functionality can solve the problem. Have you looked at the Assertion TestStep in particular Groups they allow you to set up AND/OR groups. From the docs about the OR condition:

         

        "At least one assertion within the group must evaluate to VALID to assert a group PASSED condition."

         

        Thus you can put an assertion test step after your SOAP step and then move your assertions from the soap step into the assertion test step.

         

        But looking at your last line:

         

        "and continue loop until assertion 2 failed"

         

        If you really want to remember a fail condition from a previous run through the loop and combine it with a check from the current run through the loop, then yes you'll probably need Groovy. Very briefly, you'd want to remove your assertions from the SOAP test step, then within your Groovy script get and check you data (you can use the point and click functionality to get the data) and then look at saving relevant information to the context for retrieving and checking later on. You can then use the fail method of the testRunner object that the Groovy script provides.