cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
Contributor

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 5
Highlighted
Contributor

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

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.

Highlighted
Community Hero

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

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

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Contributor

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

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?"

Highlighted
Community Hero

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

@SmartBear217 

 

Apologies - I focused on the fact that you were trying to use testRunner in a script assertion - not the other part of your post

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Moderator

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

Hi all,

 

@SmartBear217, have you managed to find the answer to your question? What stage are you on?


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to change request body before sending it to the server for the TechCorner tag!


Scripts created in June:
- A script to generate a request body based on data from Datasource
- A script to go through all response nodes and check the value of the required field
- A Dispatching script to get responses based on the values in Request Body
- A script to add a new tag and assign it to all TestCases in a TestSuite
- A script to add a new tag and assign it to all TestCases in a TestSuite
Top Kudoed Authors