How can we save the XML validation (Assertion) error message (we can see in ITR event tab assertion event result) in properties.

book

Article ID: 36847

calendar_today

Updated On:

Products

CA Application Test Service Virtualization CA Continuous Application Insight (PathFinder) CA Service Virtualization (DevTest / LISA / VSE / Application Test)

Issue/Introduction

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.

 

  •   Add a LISA javaScriptStep with this code -

-------------------------------------------------------------------------------------------------------------------------------------------

//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.

 

  • Remove listener.

-------------------------------------------------------------------------------------------------------------------------------------------

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 https://communities.ca.com/message/241746057#241746057

 

Environment

Release: LSASVR99000-8.3-LISA-Server
Component: