Run an overriding user-defined test object method

Relevant for: GUI tests and components

You can register a user-defined function to (temporarily) override the functionality of an existing test object method for a test object class.

When a user-defined function runs instead of the test object method it overrides, if it calls any overridden test object methods, the standard functionality of those methods is used.

When you call the user-defined function directly, if it calls any overridden test object methods, their overriding user-defined functions are used.

Example: A Registered User Function That Calls the Test Object Method It Overrides

Suppose you want to report the current value of a Web edit box to the run results before you set a new value for it. You can override the standard UFT One Set method with a function that retrieves the current value of an edit box, reports that value to the run results, and then sets the new value of the edit box using the standard Set method.

The function (and its registering line) would look something like the following:

Function MySet (obj, x)
    dim y
    y = obj.GetROProperty("value")
    Reporter.ReportEvent micDone, "previous value", y
    obj.Set (x)
End Function
RegisterUserFunc "WebEdit", "Set", "MySet"

When a test or component step uses the WebEdit.Set method, the overriding MySet function runs, and in turn, calls the original UFT One WebEdit Set method.

However, when a test or component step uses the MySet function, the function runs and calls the overridden WebEdit.Set method, running the MySet function once more. This time, MySet calls the original UFT One WebEdit Set method.

Back to top

Example: A Registered User Function That Calls a Test Object Method That Is Overridden by Another Function

Suppose you want to override the VbButton's standard Click method to always perform a double click. In addition, you want to override the standard UFT One DblClick method with a function that retrieves the text of the button and reports it to the run results before double-clicking the button.

The function (and its registering line) would look something like the following:

Function MyDblClick (obj, x, y, button)
    dim button_name
    button_name = obj.GetROProperty("text")
    Reporter.ReportEvent micDone, "Clicking", button_name
    obj.DblClick x, y, button
End Function
RegisterUserFunc "VbButton", "DblClick", "MyDblClick"
Function MyClick (obj, x, y, button)
    obj.DblClick x, y, button
End Function
RegisterUserFunc "VbButton", "Click", "MyClick"

When a test or component step uses the VbButton.Click method, the overriding MyClick function runs. In this situation, MyClick will then run the original UFT One VbButton DblClick method.

When a test or component step uses the MyClick function, the function runs and calls the overridden VbButton.DblClick method, running MyDblClick. MyDblClick reports the button text to the run results and then calls the original UFT One VbButton DblClick method.

To ensure that the MyClick function always runs the overridden behavior for DblClick method, you could call MyDblClick directly within MyClick.

Back to top