Forum Discussion

JanPot's avatar
JanPot
Occasional Contributor
7 years ago

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

  • 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.

     

     

  • JHunt's avatar
    JHunt
    Community Hero

    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.

     

     

    • JHunt's avatar
      JHunt
      Community Hero

      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.

       

    • JanPot's avatar
      JanPot
      Occasional Contributor

      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.

       

    • ddineesh's avatar
      ddineesh
      New Contributor

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