Forum Discussion

SmartBear217's avatar
SmartBear217
Contributor
5 years ago

How do I import TestRunner/How do I fail a test case without testRunner?

For a groovy assertion, testRunner is not available apparently. Sometimes at the top it says testRunner but this only says "Script is invoked with log, context and messageExchange variables".

 

So I cannot do testRunner.fail()

 

How do I import testRunner? 

or How do I fail the test case without the testRunner?

 

 

5 Replies

  • Update: I found one possible solution here: https://onebyteatatime.wordpress.com/2009/04/01/soapui-tips-n-tricks-part-1/

     

    I still have to test it though.

     

    Possible solution:

    I cannot refer to testRunner object in my groovy assertion. How do I access a test-case or step therein from my groovy assertion?

    This was quite an interesting one. typically when you want to access a current test case you would use a syntax

    testRunner.testCase

    this works perfectly fine in a plain groovy step or setup or tear down scripts. However, when you try referring to testRunner within a groovy assertion step, soapUI throws exception. The workaround to this is accessing testCase or test step via ‘context’ object. So you can use a syntax

    context.getTestCase().getTestStepByName(“MyStep”) OR
    context.getTestRunner()

    depending on your need.

    • richie's avatar
      richie
      Community Hero

      Hi SmartBear217 

       

      One of the decent groovy scripters on here will be able to explain better than  I - I only play with it - but what you've found is correct - for a Groovy TestStep - testRunner is available, but for a script assertion it isn't, so you have to use messageExchange 

       

      For example - the following works in a groovy script - the next is part of a script to grab a response header called 'originalFileName' that was generated from a step entitled 'POST Request (create call)'

       

      //Takes one of the elements of the response Header
      def value = testRunner.testCase.testSteps["POST Request (create call)"].testRequest.response.responseHeaders["originalFilename"]

      Whereas for a script assertion to do the same thing I had to use messageExchange

       

      //Takes one of the elements of the response Header
      def value = messageExchange.modelItem.testStep.testCase.testSteps["POST Request (create call)"].testRequest.response.responseHeaders["originalFilename"]

      Does that help at all?   As I say - I'm not a groovy scripter I just play around with it - one of the other chaps on here will be able to explain it all

       

      cheers,

       

      rich

       

       

      • SmartBear217's avatar
        SmartBear217
        Contributor

        Thanks for the reply but I'm not sure this helps because the question was "How do I fail the test case without the testRunner?"