Saving the XML validation (Assertion) error message into a property
search cancel

Saving the XML validation (Assertion) error message into a property

book

Article ID: 36847

calendar_today

Updated On:

Products

CA Application Test CA Continuous Application Insight (PathFinder)

Issue/Introduction

Added an XML validation assertion in a test step. This assertion is validating xml details and returning an error message. The ITR-->Test Events tab show the assertion result.  Is there any way to save this assertion error message to a property?

Environment

All supported LISA/DevTest releases

Resolution

It can be done by adding "EVENT_ASSERT" listener to capture the assertion result and save it into a LISA property. Follow the below steps.

* Add an Execute Script and add the below JavaScript code: This will add a listener for assertion events.This should be before your assertion step or first step of your LISA test 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 it can be later removed.

testExec.getTestEventMgr().addListener(custom_listener,com.itko.lisa.test.TestEvent.noFilter); //Add the listener to the testcase

* Run your assertion. Save LISA property - fi_assertionResult value to a file.

* Remove listener: Add an Execute Script or Scripted Assertion with the below JavaScript code to remove the added Listerner. This should be added after you saved the results to a File.
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