Forum Discussion
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.
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
- SmartBear2175 years agoContributor
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?"
Related Content
- 4 years ago