list of test step results in groovy script

8.3k views Asked by At

I'm trying to figure out a way to get a list of (names) of just the failed test steps, currently the below code is giving me all the names

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each
{
    log.info (it.name)
}

Now I'm not sure how to move on from here and the get the failed status of each step in that list

1

There are 1 answers

6
albciff On BEST ANSWER

You can use the follow approach: Get the assertion status of the testSteps, and then check if the status is FAILED, UNKNOWN or VALID. You can use the follow groovy code to do so:

import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus

def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each{
    // check that testStep has assertionStatus 
    // (for example groovy testSteps hasn't this property since
    // there is no asserts on its)
    if(it.metaClass.hasProperty(it,'assertionStatus')){
        if(it.assertionStatus == AssertionStatus.FAILED){
            log.info "${it.name} FAIL..."
        }else if(it.assertionStatus == AssertionStatus.VALID){
            log.info "${it.name} OK!"
        }else if(it.assertionStatus == AssertionStatus.UNKNOWN){
            log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
        }
    }
}

Take in account that not all testSteps has assertionStatus (like for example groovy testStep, this is why I check the property in the code above).

This code can be used simply in a groovy testStep or as a tear down script for your testCase.

If you need a different approach to work for all testSteps instead of only for testSteps which has assertionStatus properties, you can use the follow code. However note that the first approach advantage is that if you want you can use it as a simply groovy testStep, the alternative counterpart is that the follow script can only be used as a tearDownScript and can only works correctly with the whole test execution since the results are only available at this context:

testRunner.results.each{ testStepResult ->
    log.info "${testStepResult.testStep.name} ${testStepResult.status}"
}

testStepResult is an instance of com.eviware.soapui.model.testsuite.TestStepResult you can take a look at api to get more info.

Hope this helps,