Event Handler
Description
Receives a DOM event on the control.
Syntax
function On<event>(inParam, eventObj)
Argument | Type | Description |
---|---|---|
inParam |
Variant
|
The last parameter passed to RegisterForEvent. |
eventObj
|
Object
|
The event object as passed by the browser. The object may vary between browsers.
|
Return Value
true on success, otherwise false.
Remarks
- The event handler can call the _util.Record method to write a test step. It can also write to the log and perform any application-specific activities. The test object method used in the Record call must be implemented by the toolkit unless there is a default implementation.
- The event handler can use predefined mouse-button constants when checking the values of the event's button property.
When calling _util.Record, ensure that signature of the test object method you record conforms to the definition you created in the test object configuration file. The arguments must be in the correct order and be of the correct type. If you are recording a step that calls a method that is not defined by your custom toolkit support set, the step you record must conform to signature of the method specified in the UFT One object model.
Use these constants (without quotes) or values (defined in the common.js file):
Calling RegisterForEvent
If the event changes the DOM by adding elements to the control, you may need to call the _util object method, RegisterForEvent, to listen to events on the new elements. For example, opening a submenu may add new menu elements whose events must be recorded.
Order of Events
Your event handler is called before the browser handles the event. If the step to be recorded as a result of that event is dependent on the state of the control after the event, take into account that the application has not yet responded to this event.
For example, if your event handler is listening for a Click event on a toggle control, the step you record depends on whether the Click event causes the control to turn on or off. Since the browser has not yet handled the event, if the current state of the toggle is on, you record a test step to turn the toggle off.
However, there may be cases where the browser already responded to an event that occurred before the event you are listening to, and has already changed the state of the control. When designing your event handler, be sure you understand the full sequence of events.
Example
In this example, the event handlers will be passed a reference to the panel on which the event occurred.
function ConnectToEvents(elem)
{
var stackPanels = getStackPanelItems(_elem);
// Listen to click events on each of the panel headers in the StackPanel.
for (var i = 0; i < stackPanels.length; i++)
{
_util.RegisterForEvent(stackPanels[i], "onclick",
"OnPanelSelect", stackPanels[i]);
}
return true;
}
The event handler writes to the log files and calls the _util.Record method to write a test step.
function OnPanelSelect(panelHeader, eventObj)
{
// Trim the new line before the title.
var selectedPanelTitle = trim(panelHeader.innerText);
_util.LogLine("Stack Panel mouse click event on panel " +
selectedPanelTitle,
LogSeverity_Information,
0, GWT_ACCORDION_CATEGORY);
// Create the test step:
// Select <panel title>
var arr = new Array();
arr.push(selectedPanelTitle);
_util.Record("Select", toSafeArray(arr), 0);
return true;
}