Ask a Question

Failing a Groovy Script Test Step

Ascendum_Soluti
Occasional Contributor

Failing a Groovy Script Test Step

I am running a groovy script in one of my test step. When the groovy script runs, it runs to completion. If, however, the logic dictates that the step should fail, how would I fail the test step so that the test case would stop?

Thanks,
Bill B.
11 REPLIES 11
M_McDonald
Super Contributor

Re: Failing a Groovy Script Test Step

I think this should work.

testRunner.fail("your reason for failing the test")
"Ignorance more frequently begets confidence than does knowledge"
solai
New Contributor

Re: Failing a Groovy Script Test Step

Hi,

Am trying to run groovy script step that internally executes REST test step based on the provided input data (reads from excel), here am trying to fail the test case in the groovy step based on the returned assertion status using testRunner.fail() this works properly while executing only the groovy test step but if I run through the whole test case it's not iterating and struck in the second iteration Any idea to solve this ? 

Radford
Super Contributor

Re: Failing a Groovy Script Test Step

Have you checked the test case basic options for your test case that contains the test step in question? In particular the "Fail Test Case on Error" option.

solai
New Contributor

Re: Failing a Groovy Script Test Step

Yes that one is unchecked

smadji
Contributor

Re: Failing a Groovy Script Test Step

I have a similar case and this is what I do:

 

The groovy starts by calling the rest call (in my case its 3 steps on their own test suite at the end of my suite). They run and validate whatever they validate - for example that the company is in the DB. the last step returns a global property (at the project level) with value 1 or 0

Now back to the groovy, after it executes the rest calls suite it has a delay to let them run (they go to 3rd party)

Following that - I have an assertion that the value in the global property is '1'. If its 0 - I output that the company doesn't exists. If its 1 I get success and move on to the following step

krabhishek_30
Occasional Contributor

Re: Failing a Groovy Script Test Step

testRunner.fail() fails the whole test case.

I have a test case where

- I run a http call,

- validate data returned by the call and then,

- iterate to the http call

This keeps on happening until a condition is satisfied.

 

The problem is, when i use testRunner.fail() it fails the whole test case and the iteration stops. I want to fail the current iteration and then move on to next iteration.

 

Is there a way.

mpartyka
Contributor

Re: Failing a Groovy Script Test Step

 

try this ?.

 

- run a http call,

- validate data returned by the call with an assertion (either as separate assertion test step, or on the http call itself)

- groovy step to direct flow to appropriate test step based on assertion status

- loop back to the http call if test assertion fails

- jump to final test step if assertion passes

 

Note:   TestCase option 'Abort on Error' must be unchecked (option set on the entire test case) or the test will stop processing with the first failure. 

 

groovy would be similar to this ... 

 

def assert_status_token = testRunner.testCase.getTestStepByName("Assertion").getAssertionStatus().toString()
if (assert_status_token == 'FAILED')
{
testRunner.gotoStepByName( 'RecordErrors' )
}
else
{
testRunner.gotoStepByName( 'DataSource Loop' )
}

nmrao
Community Hero

Re: Failing a Groovy Script Test Step

May you should consider creating a separate question with the details instead of reviving an old thread.


Regards,
Rao.
Manoj1
Visitor

Re: Failing a Groovy Script Test Step

Hi All,

 

As am a beginner in the learning to Groovy, i request you to provide/suggest me the script should read the soap response and log information.

 

Thanks

Manoj

cancel
Showing results for 
Search instead for 
Did you mean: