Enables you to add new methods to test object classes or change the behavior of an existing test object method during a run session.
When you use this statement, UFT One uses your user-defined function as a method of the specified test object class for the remainder of the run session, or until you unregister the method.
If the specified method name does not already exist for the test object class, it becomes a new method for the test object class. If the method name is a defined UFT One method for the test object class, your definition (temporarily) overrides the existing functionality of the specified method.
For more details on user-defined functions, see the Micro Focus UFT One User Guide.
RegisterUserFuncTOClass, MethodName, FunctionName, SetAsDefault
The test object class for which you want to register the method.
You cannot register a method for a UFT One reserved object (such as Recover, Reporter, and the other objects listed in the Utility Objects section of the Micro Focus UFT One Object Model Reference for GUI Testing).
The method you want to register. The method name cannot contain spaces.
The name of your user-defined function. The function can be located in your action or in any library file associated with your test or component.
Optional. Indicates whether the registered function is used as the default operation for the test object.
Default = False
Note: When you select a test object in the Keyword View or Step Generator, the default operation is automatically displayed in the Operation column (Keyword View) or Operation box (Step Generator). For more details, see the Micro Focus UFT One User Guide.
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. (See UnregisterUserFunc Statement.)
UFT One clears all function registrations at the beginning of each run session.
When UFT One runs a registered method, it sends the test object as the first argument. For this reason, any user-defined function that you register as a test object method must have at least one argument, which receives the test object.
If you register a user-defined function to override an existing test object method, then after the test object argument, the function must have the same number of arguments as the method it overrides.
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
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("Advantage Shopping").Page("Advantage Shopping").Link("UserMenu").Click Browser("Advantage Shopping").Page("Advantage Shopping").WebEdit("username").Set "tutorial" UnRegisterUserFunc "WebEdit", "Set"
- CallServiceTest Statement
- CreateObject64 Statement
- DescribeResult Statement
- ExecuteFile Statement
- ExitAction Statement
- ExitActionIteration Statement
- ExitComponent Statement
- ExitComponentIteration Statement
- ExitTest Statement
- ExitTestIteration Statement
- GetLastError Statement
- InvokeApplication Statement
- LoadAndRunAction Statement
- LoadFunctionLibrary Statement
- ManualStep Statement
- Print Statement
- RegisterUserFunc Statement
- RunAPITest Statement
- SetLastError Statement
- UnregisterUserFunc Statement
- Wait Statement