List of test step results in groovy script
I am trying to figure out a way to get the list (names) of only failed test steps, currently the below code gives me all the names
def TestCase = testRunner.getTestCase()
def StepList = TestCase.getTestStepList()
StepList.each
{
log.info (it.name)
}
Now I am not sure how to go from here and get the failed status of each step in this list
source to share
You can use the following approach: get the approval status of the test steps and then check if the status is FAILED, UNKNOWN, or VALID. You can use the following groovy code for this:
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)"
}
}
}
Note that not all testSteps have an assertionStatus (like groovy testStep, which is why I am checking the property in the code above).
This code can be used simply in groovy testStep
or as tear down script
for your test table.
If you need a different approach to work for all testSteps, not just testSteps, which has properties assertionStatus
, you can use the following code. Note, however, that the advantage of the first approach is that if you want to use it as simply groovy testStep
, an alternative analogue is that the subsequent script can only be used as tearDownScript
and can only work correctly with the entire test execution, since it results
is only available in that context :
testRunner.results.each{ testStepResult ->
log.info "${testStepResult.testStep.name} ${testStepResult.status}"
}
testStepResult is an instance com.eviware.soapui.model.testsuite.TestStepResult
you can look at the api for more information.
Hope it helps,
source to share