RegisterUserFunc in QTP automation testing : Enables you to add new methods to test objects or change the behavior of an existing test object method during a run session.
When you use this statement, QuickTest uses your user-defined function as a method of a specified test object class for the remainder of a run session, or until you unregister the method.
If the specified method name does not already exist for the test object, it becomes a new method for the object. If the method name is a defined QuickTest method for the object, your definition (temporarily) overrides the existing functionality of the specified method.
Notes:
A registered method applies only to the test or library file in which you register it (or to any tests calling an action containing a RegisterUserFunc statement).
For tests, if you register a function within a reusable action, it is recommended that you unregister the method at the end of the action.
QuickTest clears all function registrations at the beginning of each run session.
For more information on registering user-defined functions, see the HP QuickTest Professional User Guide.
Syntax
RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault
Examples
The following example uses the RegisterUserFunc method to create a new Copy method for the WinEdit test object that copies all the text in an edit box to the Windows Clipboard.
Sub Copy (edit)
Edit.Click 3, 3
Edit.SetSelection 0, Len(Edit.GetROProperty("text"))
Edit.Type micCtrlDwn + "c" + micCtrlUp
End Sub
RegisterUserFunc "WinEdit", "Copy", "Copy"
' Now you can call the new method
Dialog("Login").WinEdit("Agent Name:").Copy
Dialog("Login").WinEdit("Agent Name:").Copy
The following example uses the RegisterUserFunc method to modify the behavior of the WebEdit.Set method as defined in the MySet function. The new behavior enables the Set method to retrieve and report the default value of the edit box before the new value is entered.
Function MySet (obj, x)
dim y
y = obj.GetROProperty("value")
Reporter.ReportEvent micDone, "previous value", y
MySet=obj.Set(x)
End Function
RegisterUserFunc "WebEdit", "Set", "MySet"
Browser("MercuryTours").Page("FindFlights").WebEdit("Country").Set "Canada"
UnRegisterUserFunc "WebEdit", "Set"
Post a Comment