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.

Event handler overview

You use event handlers to help your test recover smoothly from behavior of the application that either:

  • Does not occur in every run. For example, during login, the user 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 to handle such 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. An event handler calls a function to handle a condition only if the 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

You use the Event handler editor to define event handlers.

To create an event handler:

  1. Click the Event handler editor button event handler editor in the Toolbar.
  2. Click the add button add a transaction 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 the properties for the event handler. For details, see Event handler editor .

    If a function that handles this event does not exist, close the Event handler editor and create the function. For details, see TruClient functions and function libraries.

    After creating the function, reopen the editor and select the library and the function.

Back to top

Event handler editor

The Event handler editor dialog box enables you to define events handlers and their properties.

UI Element Description
<Event handlers panel>

add a transactionAdd Event Handler. Add an event to the event handler.

Delete Event Handler. Delete an event from the event handler.

General
  • Name. Enter a name for your event handler.
  • 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. Select the check box to enable other event handlers to run during the run of this event.
  • Event can be triggered during the entire script. Select to allow TruClient to listen for the event throughout the test run, and call the event handler whenever the event occurs.

    Clear the Event can be triggered during the entire script checkbox to listen for the event during only part of the run. If you clear this box, the Start and End fields are displayed, where you can specify the range of steps where the event can be triggered.

  • Disable this event handler. Disables the event handler without deleting it.

  • Event type. You can select:

    • Dialog opened. When the specified dialog box is opened, the event handler is triggered.
    • Object exists. If object exists during replay, the event handler is triggered.
    • Property exists on object. If the property of an object meets the defined criteria, the event handler is triggered.

Object

Choose an object. Select the object from your application that will trigger the event handler.

After you select an object, the following options are displayed:

  • Name. The name of the object.
  • ID method. For explanations of the ID method options, see Object identification.

  • Value, Property, Condition. Displayed when the event type is Property exists on object. Define the relevant criteria.

Handler

The handler function must be in a library.

  • Library. Enables you to select the library containing the function.
  • Function. Enables you to select the function.
  • Arguments. If the selected Function has function parameters, this field is displayed. Enter the argument values.

Back to top

See also: