Arah
4 years agoOccasional Contributor
Assert if any TestStep failed
Hey,
how can I assert if any of the TestSteps failed using Groovy Script? I have written a groovy script script that among other things run another TestCase and I want it to assert every TestStep (in called TestCase) if it failed. Currently it check TestSteps but it does not include Groovy Script Steps (Groovy Script steps that have asserts inside of them).
This is what I have so far...
//Get TestStepList from called Project
def assertFinishedStatus = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepList()
//Assert if any step with assertions failed in called TestCase
def moduleStatus = true;
assertFinishedStatus.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 "TestStep: ${it.name} - - - - - - - - - - - - Status: FAILED"
return moduleStatus = false;
}else if(it.assertionStatus == AssertionStatus.VALID || it.assertionStatus == AssertionStatus.UNKNOWN){
log.info "TestStep: ${it.name} - - - - - - - - - - - - Status: OK!"
return moduleStatus = true;
}
}
}
assert(moduleStatus != false)