Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
15 years ago

print assertion name, status, and message via groovy

Hello,
I have a testcase tear down script, which need to print the assertion name, status, and error message (if any)

testcase example

data source
soap step 1
rest step 1
jdbc step 1
data source loop

so printing out something like this to a file would be desired

row=1
soap step 1
-- soap assertion - passed
rest step 1
-- contain assertions - failed - some message
jdbc step 1
-- xpath assertion - failed - some message


row=2
soap step 1
-- soap assertion - passed
rest step 1
-- contain assertions - passed
jdbc step 1
-- xpath assertion - failed - some message

Thanks
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Ali,

    If you want information on the assertion-level you would have to create a script before the loop that goes through the list of assertions for each teststep:

    def soapStep = testRunner.testCase.testSteps["soap step 1"]
    for( assertion in soapStep.assertionList )
    {
    log.info "Assertion [" + assertion.label + "] has status [" + assertion.status + "]"
    for( e in assertion.errors )
    log.info "-> Error [" + e.message + "]"
    }

    etc..

    does that help?

    /Ole
    eviware.com
    • ritesh23487's avatar
      ritesh23487
      Occasional Contributor

      HI Ole,

       

      I have a test Suite with 20 Test Cases. From Reporting point of view i am expecting to capture the failure of any Test Step in a Specific Test Case.

      Could you please assist in simple groovy script (which is populated at the end when all the test cases have been executed)  which captures all the Failure Test Step Name from all the test cases in the particluar Test Suite .

       

      Thanks

      Ritesh Bharuka

  • alibaba82's avatar
    alibaba82
    Super Contributor
    Hi /Ole,
    I tried the code below in my testcase teardown script but it only prints out the assertion name/value for the teststep for the last loop.
    My datasource causes the teststep to be executed 5 times, so I am trying to print out 5 sets of assertion name/value.

    Thanks

    Ali
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    yes, you will need to do this inside the testcase to capture the status of all assertions for all iterations, ie in a groovy script teststep before the datasourceloop. You could save the data to a temporary collection in the context instead of logging it out and then use that collection in the tearDown script?

    regards!

    /ole
    eviware.com