Share this page

# Event handlers

This section describes TruClient event handlers, and how to use them to manage unexpected or unpredicted events that can occur during script replay.

In this topic:

## Event handler overview

Your application may include behavior that either:

- Does not occur in every run. For example, during login, the user may sometimes gets a notification: “Server is busy. Please wait for 10 seconds and try again”.

- Occurs at unpredictable times. For example, the application displays a survey popup at random times.

If you record or add a step for this behavior, your script may fail when the behavior does not occur. If there is no step to handle it, the script may fail when the behavior does occur.

You use event handlers to help your test recover smoothly from this type of behavior. An event handler calls a function to handle a condition, but only if that condition occurs.

You can create an event handler for these events:

- Object event. Used when an object-related event occurs. For example, a certain object appears on the page, or a certain object property gets a certain value.

- Dialog event. Used when a dialog box pops up. For example, an alert or a prompt.

Back to top

## Create an event handler

Use the Event handler editor in the Development window to define event handlers.

To create an event handler:

1. Click the Event handler editor button on the Toolbar.

2. Click the add button in the editor to add a new event handler.

   An error icon is displayed next to the handler name, until enough information is added to define the handler.

3. Enter a unique name for the event handler.

4. Define the General properties:

   UI Element | Description
   --- | ---
   Execute only once | Executes the event handler only once during the current iteration (it resets to zero when the iteration ends).
   Allow other handlers to interrupt | Enables other event handlers to run during the run of this event.
   Event can be triggered during the entire script | When the checkbox is selected, TruClient listens for the event throughout the test run, and calls the event handler whenever the event occurs. When the checkbox is not selected, TruClient listens for the event during a specified part of the run. Select the range of steps where the event can be triggered in the Start and End fields.
   Disable this event handler | Disables the event handler without deleting it.
   Event type | Select an option: Dialog opened. When the specified dialog box is opened, the event handler is triggered. Object exists. If the specified object exists during replay, the event handler is triggered. Property exists on object. If the property of the specified object meets the defined criteria, the event handler is triggered.

5. If the event type is for a specified object, click Choose an object and select the object that will trigger the event handler.

   After you select an object, you can edit the Object properties:

   UI Element | Description
   --- | ---
   Name | The name of the object for action.
   ID method | Select the method to identify the object. For details, see Object identification.
   Value | Displayed when the event type is Property exists on object. Define the value within the object for which the trigger criteria applies.
   Property | Displayed when the event type is Property exists on object. Select the value property that triggers the event handler.
   Condition | Displayed when the event type is Property exists on object. Select the property condition that triggers the event handler.

6. Define the function properties in the Handler area. For details on functions, see Work with function libraries.

   If a function to handle this event does not yet exist, close the Event handler editor and create the function. Then reopen the editor.

   UI Element | Description
   --- | ---
   Library name | Select the library containing the function.
   Function name | Select the function.
   <Arguments> | If the selected function has arguments, a separate field is displayed for each defined argument. Enter the argument values.

7. Check that there is no longer an error icon displayed next to the event handler name, to make sure that you have successfully defined the handler.

   Click Save.

Back to top

See also:

- Enhance scripts

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1 All View Local Help Center View Online Help Center Version: