Forum Discussion

webserviceAutom's avatar
webserviceAutom
Occasional Contributor
11 years ago

Log Assertion List and its Status at Test Suite Level

Hi,

I would like to capture the name and status of all assertions in a Test Suite Tear Down.Is there a way to access AssertionList (Name, Status) for all test cases at a Test Suite Level?

3 Replies

  • I did this today actually


    //Change to teststep name required
    def soapStep = testRunner.testCase.testSteps["XXXXXXXXX"]
    def AllAsserts = [] as Set
    def ErrorAsserts = [] as Set
    for( assertion in soapStep.assertionList )
    {
    //Log Assertions as individual lines
    //log.info "Assertion [" + assertion.name + "] has status [" + assertion.status + "]"

    //Add each assertion to a list
    AllAsserts.add("Assertion [" + assertion.name + "] has status [" + assertion.status + "]")

    //Get all the asserts with an error
    for( e in assertion.errors )
    //Add each assertion to a list with errors with error message
    ErrorAsserts.add("-> Error [" + assertion.name + "] : [" + e.message + "]")

    //Log Assertions as individual lines
    //log.info "-> Error [" + assertion.name + "] : [" + e.message + "]"
    }

    //Log All asserts
    log.info AllAsserts
    //Log Error asserts
    log.info ErrorAsserts

    //Write into ContentAssertions property list
    testRunner.testCase.testSteps["ContentAssertions"].properties['XXXXXXX - AllAsserts'].setValue(AllAsserts.toString());
    testRunner.testCase.testSteps["ContentAssertions"].properties['XXXXXXX - ErrorAsserts'].setValue(ErrorAsserts.toString());


    As you can see above, I then copied the outputs as a list to ContentAssertions (a properties step) this way I could output the result later using the DataSink. Hope that helps!