Typical event handler scenario
In this scenario, Suzy is developing a script. Every now and then, a message pops up asking her to sign up for weekly tips. The message appears at unexpected intervals while performing the business process steps.
Suzy decides to create an Event Handler that closes this message whenever it appears. Here are the steps she follows to create the event handler:
Suzy opens the Event Handler Editor from the main toolbar and clicks the button to add a new Event Handler.
Because the message can pop up at any time, in the General section, Suzy selects Event can be triggered during the entire script.
The handler is an “Object” type because the message appears within a regular DOM object and not within a browser dialog box.
Suzy then clicks Click to choose an object and highlights the “SIGN ME UP!” button.
After she chooses the object, TruClient creates identification for it:
Suzy sets the Event Type to “Object Exists” so the event handler will be called each time the message pops up.
Now that the event is defined, Suzy creates a function that ignores the prompt and closes the message. To create the function:
She closes the Event Handler Editor and, if the message is not displayed, she browses the application until it pops up.
She starts recording and closes the message:
She then stops the recording. TruClient recorded a navigation step and the close step. Suzy is only interested in the close step.
To create the function from the close step, she selects the step, right clicks to open the context menu, and selects Group Into > New Function.
When the Create new function dialog box appears, she enters a function name and a library name and clears the Replace steps with function call option so the script itself does not call this function. She wants only her event handler to call the function.
Now Suzy has a new function that contains a single step that closes the message.
The new function is listed in Function Libraries.
Now that Suzy has the function she needs, she opens the Event Handler Editor again and chooses CloseSignUp as the handler function.
Now she can record the business process as usual.
When she encounters the popup message during recording, she stops the recording and deletes the steps associated with it, since the event handler will close the message whenever it pops up in replay.