Creating event handlers

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

Getting ready

Before creating the event handler, we need to add the Events project item if it is not added to project yet:

  1. Right-click on the project name in the Project Explorer tab and navigate to Add | New Item.
  2. In the opened Create Project Item window, select the Events item and click on OK:
    Getting ready

How to do it...

To create the event handler for the OnLogError event we need to perform the following steps:

  1. Expand the Events node in the project and double-click on the General Events item.
  2. In the Events to Handle list, expand the General Events node and select the OnLogError item.
  3. Click on the New button which is located inside the OnLogError element:
    How to do it...
  4. In the New Event Handler window, select the script unit where you want to create the handler and click on the OK button:
    How to do it...

    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.

How it works...

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.

Note

Please note that event's handlers should have exactly the same parameters as they are expected by TestComplete, that's why it is better to create event's handlers by TestComplete means.

There's more...

To remove an existing event handler (not the function itself), right-click on its name in the Events to Handle list and select menu item Remove Event Handler.

If you want to completely remove the function, simply remove it from the unit in the editor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.39.144