Question:
I have added an XML validation assertion in my test step. This assertion is validating my xml details and returning an error message details. Is there any way to save this assertion error message to a property?
Answer:
We can Add "EVENT_ASSERT" listener to capture the assertion result and save it to LISA property.
-------------------------------------------------------------------------------------------------------------------------------------------
//Create a custom eventlistener that handles the event_assert event
var custom_listener = new com.itko.lisa.test.TestEventListener(){
public void testEvent(com.itko.lisa.test.TestEvent testevent){
if(testevent.getEventId() == com.itko.lisa.test.TestEvent.EVENT_ASSERT){
testExec.setStateValue("fi_assertionResult",testevent.getLongDesc()); //tell what to do with the event. In this case stores the long message in the fi_assertionResult property
}
}
};
testExec.setStateValue("Custom_Listener",custom_listener); //Stores a referens to the eventlistener so we can later remove it
testExec.getTestEventMgr().addListener(custom_listener,com.itko.lisa.test.TestEvent.noFilter); //Add the listener to the testcase
-------------------------------------------------------------------------------------------------------------------------------------------
This will add a listener for assertion events.This should be before your assertion step or first step of your LISA test code.
Run your assertion. Save LISA property - fi_assertionResult value in a file. This is what you need.
-------------------------------------------------------------------------------------------------------------------------------------------
var custom_listener = testExec.getStateObject("Custom_Listener");
if(custom_listener !=null){
testExec.log("Removing listener :" + custom_listener );
testExec.getTestEventMgr().removeListener(custom_listener); // Remove the listener from the testcase
}else{
testExec.log("Unable to remove listener :" + custom_listener );
}
-------------------------------------------------------------------------------------------------------------------------------------------
Additional Information:
Sample test case with this code is available at