Adding Events to Event Controls

Applies to TestComplete 12.60, last modified on September 17, 2018

In TestComplete, you can create event handlers for TestComplete engine events and for events of ActiveX objects that reside in external applications (see Handling Events - Overview).

In order for TestComplete to be able to handle an event, this event should be added to an Event control. TestComplete events are added to these controls by default. As for events of external ActiveX objects, you need to add them to the control manually, as TestComplete does not “know“ about these events. You may also need to add a TestComplete event to the control if this event was removed from the control. The general procedure of adding events to an Event control is the same for both TestComplete and external events (see below). After you add an event to the control, you can create an event handler for this event.

To add events to an Event control, follow the steps below:

  1. If you are going to handle an event of an ActiveX object that resides in an external application, and if this application is not a COM server, you need to compile the application as an Open Application.

  2. Event controls, to which you can add events, are shown as child nodes of the Events project item in the Project Explorer panel. By default, this project item contains only one child, GeneralEvents.

    Event Control in the Project Explorer

    Right-click the needed Event control (for instance, GeneralEvents) in the Project Explorer and select Edit from the context menu. TestComplete will show the Event Control editor in the Workspace panel.

    Event Control Editor

    Click the image to enlarge it.

  3. In the Source object edit box of the editor, specify the event source. This can be either the TestComplete engine or an ActiveX object:

    • To handle TestComplete events, select TestComplete general events from the drop-down list of the Source object box.

    • To specify the needed ActiveX object, enter any of the following:

      • The class id of the object.

      • The program id of the object.

      • The full name of the object (you can find it in the Object Browser panel).

      • The file name (including the path) of the type library that holds the declaration of the object.

        Normally, stand-alone type libraries have the .tlb extension. However, quite often, type libraries are included in .ocx, .dll and .exe modules. In this case, you need to specify the name and the path of this .ocx (.exe or .dll) module.

      • GUID of the type library that holds the declaration of the object.

      You can either type this information manually, or click the ellipsis button and select the needed ActiveX object from the subsequent Select ActiveX Library dialog. You can also select a value from the drop-down list.

      As you may have already guessed, TestComplete uses this data to locate the type library that holds the object’s declaration (the type library also contains valuable information about object events). If TestComplete can get to the type library, it displays events of the object in the Available Events box.

      What If the Needed Events Do Not Appear in the Available Events List?

      • By default, the Available Events list does not display events that have the hidden attribute specified. To make these events visible, enable the Show hidden members option in the Engines - General options dialog.

      • In certain cases, some of the above mentioned variants do not work. For instance, sometimes, TestComplete does not “see” events of an object specified by program id. This happens because Windows Registry does not provide a link between the program id and the type library of the object. To solve the problem, you need to specify the full file name of the type library or the type library’s GUID.

  4. After the desired event appears in the Available Events list, you can add it to the Events to Handle list. This controls the events, which the Event control will handle. To add an event to this list, choose the needed event in the Available Events box (you can use Ctrl or Shift for multiple selection or choose Select All from the context menu to select all available events) and then drag the selected event(s) to the Events to Handle list.

    Adding Events to Be Handled

    Click the image to enlarge it.

    TestComplete will add the event to the Events to Handle list to the specified group. To indicate that this event has been added to the Event control, TestComplete will display the icon next to the event name in the Available Events list and the icon next to the group which the event corresponds to.

    Adding the OnNetJobStateChange Event

    Click the image to enlarge it.

    Note: After you have added the event, you may need to rename it as the Event control cannot include two or more events with the same name (that is, an event must have a unique name within an Event control). To rename an event, simply click its name in the Events to Handle list and type a new name. In the list, the original event name is displayed in parentheses next to the new name.
  5. (Optional). Note that one Event control can simultaneously handle events of several ActiveX objects. You can add events from several sources to the Events to Handle list by specifying different event sources in the Source object edit box and choosing the needed events from the Available Events list. To add events to be handled from other event sources, repeat steps 3 and 4.
  6. When you command TestComplete to save changes, it generates the Event control with a description specified in the TLB description edit box of the Event Control editor. This description identifies the control for other users: it is displayed in almost all dialogs that add ActiveX components to the development tools.

    TestComplete updates the Event control and automatically registers it in Windows. The control can then be used in TestComplete or in any other application.

Note: An Event control is implemented by two modules: one of them, <TestComplete>\Bin\Extensions\tcEventControl.ocx, holds the binary code of the control. The other is a type library, <EventControlName>.tlb. This library describes the events used in the project. Its location depends on the “Unregister the type library when the project is closed” setting (see "Event Control Modules" section in Handling Events - Overview).

When you save the changes made to the Event control, TestComplete does not recompile the .ocx module. It updates only the type library.

See Also

Handling Events - Overview
Removing Events From Event Controls
About Event Control Editor
Event Control Editor

Highlight search results