QTP10.com is a new and completely free website that offers help in all the versions of HP QTP (including latest version 10). More importantly, it offers free code for users of HP QuickTest Professioal. This site helps you in learning the basics of QTP and descriptive/advanced programming in (QTP) on various environments like - .Net, Infragistics, Web, Windows, etc.

Note -
This blog is NOT affiliated with HP / Hewlett-Packard in any way. The data/questions come from various sources and we have our own testing questions. I am just another Software Tester like you.

RegisterUserFunc statement in QTP

Share This Post -

Sponsored Links:

You can use the RegisterUserFunc statement to instruct QuickTest to use your user-defined function as a method of a specified test object class for the duration of a test run, or until you unregister the method.

Note: If you call an external action that registers a method (and does not unregister it at the end of the action), the method registration remains in effect for the remainder of the test that called the action.

To register a user-defined function as a test object method, use the following syntax:

RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault






Any test object class.
Note: You cannot register a method for a QuickTest reserved object (such as DataTable, Environment, Reporter, and so forth).

MethodName The name of the method you want to register (and display in QuickTest, for example, in the Keyword View and IntelliSense). If you enter the name of a method already associated with the specified test object class, your user-defined function overrides the existing method. If you enter a new name, it is added to the list of methods that the object supports.
FunctionName The name of the user-defined function that you want to call from your test. The function can be located in your test or in any associated function library.

Indicates whether the registered function is used as the default method for the test object.
When you select a test object in the Keyword View or Step Generator (tests only), the default method is automatically displayed in the Operation column (Keyword View) or Operation box (Step Generator) (tests only).

Tip: If the function you are registering is defined in a function library, it is recommended to include the RegisterUserFunc statement in the function library as well so that the method will be immediately available for use in any test using that function library.


For example, suppose that the Find Flights Web page contains a Country edit box, and by default, the box contains the value USA. The following example registers the Set method to use the MySet function to retrieve 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


End Function

RegisterUserFunc "WebEdit", "Set", "MySet"

Browser("MercuryTours").Page("FindFlights").WebEdit("Country").Set "Canada"