In order to operate with events, we need to learn how to create event's handlers in TestComplete. This recipe will guide you on creating an event handler for the OnLogError
event (this event fires every time error is posted to the TestComplete log).
Before creating the event handler, we need to add the Events project item if it is not added to project yet:
To create the event handler for the OnLogError
event we need to perform the following steps:
OnLogError
item.OnLogError
element:As a result, a new function GeneralEvents_OnLogError
will be created in the selected unit. This function will fire every time some is posted to the log and all actions from it will be executed.
It is not enough to just create a new function manually with corresponding name (for example, GeneralEvents_OnLogError
) to create an event handler. We have to perform all the previous steps described to accomplish the task.
When selecting a script unit for storing event handlers, we can create a new one by clicking on the Click here to add a new script unit... node inside the Script node. It is recommended to store all events in one separate unit for easier maintenance.
We can also use an existing function as an event handler by selecting its name in the Available Tests list in the New Event Handler window.
18.222.184.200