Forum Discussion

bindum's avatar
bindum
Visitor
2 years ago

How to get the assertion failed messages iteration wise in data driven testing

Hi Team,

How to get the execution iteration number(data set row number) along with their respective assertion failed messages in testcase teardown script when we are doing data driven testing with Datasource(Excel) and Datasource loops steps to test the same functionality with multiple test data.

 

Below is the code which i am using in teardown script. with this i am able to get the total failed assertion messages, but the problem is not clear which iteration got failed and which got passed.(means if my test case run for 10 data rows based on the datasource loop step if one test case get failed i am geeting that failed messages but how can i know which iteration got failed among the 10)

 

My question is how to get the failed assertion messages test case iteration wise not steps wise from test case terdown script.

 

def step_a = ""


suiteName=testRunner.testCase.testSuite.name
tcName=testRunner.testCase.name

for (testStepResult in testRunner.getResults() )
{

if(testStepResult.getStatus().toString() != 'PASS' )
{
// testdataRow=testdataRow+1
// log.info("TestDataRow:**********************"+testdataRow)
def testStep = testStepResult.getTestStep()

// log.info(step_a)

for( assertion in testStep.assertionList )
{
testStepType=testStep.config.type


def messages = ""
def isAssertionLogged = false
for( message in testStepResult.getMessages() )
{
//log.info("Assertion Name "+(assertion.name))
if(message.contains(assertion.name))
{
//step_a = step_a + "TestStep [ " + testStep.name + " ] finished with status " + testStepResult.getStatus().toString() + "\n"
messages = messages + testStep.name + "- Error [" + message + "]" + "\n"
isAssertionLogged = true
//log.info(messages)
break
}
}

if(isAssertionLogged)//if there is error message for the assertion, the assertion is either passed (VALID) or was not ran (UNKNOWN)
{
step_a = "Assertion [" + assertion.label + "] has status [FAILED]" + "\n"
step_a = step_a + messages


}
else
{
if(assertion.isDisabled())
{
step_a = step_a + "Assertion [" + assertion.label + "] has status [UNKNOWN]" + "\n"
//log.info(step_a)
}
else {
step_a = step_a + "Assertion [" + assertion.label + "] has status [VALID]" + "\n"

//
}
}


}

}
}

Thanks in Advance.

No RepliesBe the first to reply