By Anish Pillai Anish Pillai Posted under QTP Basic Stuff | QTP Concepts

Understanding RegisterUserFunc Syntax with Example

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

In this article, we’ll have a look at the syntax of RegisterUserFunc statement. We’ll also try to understand the syntax with the help of an example.


RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault

Argument Type Description
TOClass String The Object with which you want to register the method. Eg: WebEdit, WebButton etc
MethodName String The name that you want to use while calling the method. Eg: For a WebButton, it can be fnWebButtonClick
FunctionName String The actual name of the user-defined function, i.e. the name that is used during function definition.
SetAsDefault Boolean Optional. Indicates whether the registered function is used as the default operation for the test object.  Default Value: False

Let’s try to understand the above syntax with the help of an example. Consider a scenario where you want to create a single generic function ‘fnClick’ and use it for WebButton, Link & Image objects. Also the function calls should be different for each control. Eg: for Links the function name should be fnLinkClick, for WebButton the name should be fnWebButtonClick etc.

So RegisterUserFunc arguments would have the following values –
1. TOClass – WebButton, Link, Image
2. MethodName – fnWebButtonClick, fnLinkClick, fnImageClick
3. FunctionName – fnClick

Let’s see the code for the same.

'===== Code in Function Library =====
RegisterUserFunc "WebButton", "fnWebButtonClick", "fnClick"
RegisterUserFunc "Link", "fnLinkClick", "fnClick"
RegisterUserFunc "Image", "fnImageClick", "fnClick"

Function fnClick(objControl)
End Function

'===== Code in Action =====

If you enjoy our articles, you can join our blog to get new articles delivered directly in your inbox.


0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×