Forum Discussion

sravsand's avatar
sravsand
New Contributor
8 years ago

how to make other test steps pass/fail from groovy test step

Hello,

 

I have two steps in a test suite, one is soap request without any assertion other one is groovy test step. I want to make fail the soap request from groovy test step. I need how to write groovy script to make fail/pass of other test steps.

 

More Details:

 

i have multiple soap test steps, i am writing assertions for all test steps in one final groovy test step, if every soap test step is passed then this groovy test step will be passed, this is my current behavior but no indication of green or red to individual soap test steps. I want to write some script in groovy test step to make green/red based on respective test step pass/fail.
  •  

    Hi again,

     

    I think you wanted to also show red/green icons in the Test Case editor for the SOAP test steps. So I was researching the source code, but it's next to impossible without Assertions on the SOAP test step. In the SoapUI source code, the icon displayed is calculated from the Assertions with every update.

     

    You can change the status of the test result, and that will display red in your Test Case Log, with an optional message.
     

    import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
    
    def myStep = context.testCase.getTestStepByName("Test Request 1")
    def myResult = testRunner.results.find { it.testStep.is(myStep) }
    myResult.setStatus ( TestStepStatus.FAILED )
    myResult.addMessage("Failed coz I said so.")

    But I don't recommend modifying statuses in this way. It's best to let SoapUI do that sort of stuff itself, because we're bound to miss things doing it manually. For a ready example, the overall test still shows as OK, even when we mark the test as failed (project attached). We would need to make the Groovy script step mark the TestCase as failed also. And so on...

     

  • coolshaily's avatar
    coolshaily
    New Contributor

    same query from me.... does anybody has any answer?

     

    Thanks!

    • JHunt's avatar
      JHunt
      Community Hero

      You can put assertions in your Groovy Script.

       

      The Groovy script will always pass as long as it doesn't throw any Exceptions. When an assertion is not true, you get an AssertionException thrown. And you'll even get a nice Groovy assertion details in your log on a failure. But it works best if you display the log in a fixed width font.

       

      String myResponse = context.testCase.getTestStepByName("Test Request 1")
       .testRequest.response.responseContent
      
      // should fail
      assert myResponse?.contains("123") 

       

      ERROR:Assertion failed: 
      
      assert myResponse?.contains("123")
             |           |
             abc         false
      

      Example project attached.

       

      • JHunt's avatar
        JHunt
        Community Hero

         

        Hi again,

         

        I think you wanted to also show red/green icons in the Test Case editor for the SOAP test steps. So I was researching the source code, but it's next to impossible without Assertions on the SOAP test step. In the SoapUI source code, the icon displayed is calculated from the Assertions with every update.

         

        You can change the status of the test result, and that will display red in your Test Case Log, with an optional message.
         

        import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
        
        def myStep = context.testCase.getTestStepByName("Test Request 1")
        def myResult = testRunner.results.find { it.testStep.is(myStep) }
        myResult.setStatus ( TestStepStatus.FAILED )
        myResult.addMessage("Failed coz I said so.")

        But I don't recommend modifying statuses in this way. It's best to let SoapUI do that sort of stuff itself, because we're bound to miss things doing it manually. For a ready example, the overall test still shows as OK, even when we mark the test as failed (project attached). We would need to make the Groovy script step mark the TestCase as failed also. And so on...