cancel
Showing results for 
Search instead for 
Did you mean: 

How to know if a groovy step PASSED or FAILED ?

SOLVED
Occasional Contributor

How to know if a groovy step PASSED or FAILED ?

Hi,

 

I have some test cases with REST and Groovy steps, sometimes the Groovy steps fails (a red star icon). At the end of the test cases, I have a groovy script that creates a report with the passed or failed test. For the REST services it goes well, I can check if the assertions passed or failed with something like: "testStep.getAssertionAt(j).getStatus().toString()". But so far, I can't find a way to check the status of a previously ran Groovy steps. Those test case are made to run at night, and I would like to just have to look at the report in the morning.

 

Actually, I found a way, which is not very 'nice', with the testStep.getIcon(), if it finishes with 'failed_groovy_step.png' it means that the test failed... But there is surely a better way to know the status of a groovy script ?

 

Thanks for help.

 

Jan

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: How to know if a groovy step PASSED or FAILED ?

Hi Jan,

You should use

 

testRunner.getResults()

For instance, in a TestCase Teardown script:

 

 

Map resultOf = testRunner.getResults()
 .collectEntries { result ->  [ (result.testStep): result.status ] }

def mystep = context.getTestCase().getTestStepByName("Some step")
log.info resultOf[myStep]

In the attached project is another TestCase Teardown example, and an example of how to get the results from a TestSuite Teardown script.

 

 

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

Re: How to know if a groovy step PASSED or FAILED ?

Hi Jan,

You should use

 

testRunner.getResults()

For instance, in a TestCase Teardown script:

 

 

Map resultOf = testRunner.getResults()
 .collectEntries { result ->  [ (result.testStep): result.status ] }

def mystep = context.getTestCase().getTestStepByName("Some step")
log.info resultOf[myStep]

In the attached project is another TestCase Teardown example, and an example of how to get the results from a TestSuite Teardown script.

 

 

View solution in original post

Community Hero

Re: How to know if a groovy step PASSED or FAILED ?

The nice thing to observe with the TestSuite TearDown script is that...

runner.getResults()

... actually returns a list of TestCaseRunners.

These are the exact same runners that appear in the individual TestCase TearDown scripts as the testRunner variable.

 

Occasional Contributor

Re: How to know if a groovy step PASSED or FAILED ?

Thanks very much, it is just too super !

 

I first did it in Test case TearDown, and it worked wonderfully... After when I changed it for TestSuite, it was even better :-)

 

Much appreciated help.

 

New Contributor

Re: How to know if a groovy step PASSED or FAILED ?

It worked exactly the same way which i was expecting. Thanks for writing this.