Thursday, February 7, 2013

Register User Function

Register User Function is used to append a new method (Function/ Procedure) or to take priority over of a presented method for a certain QTP Class during run session. Register User Function is relevant for Test Objects similar to VbEdit, VbList, WebEdit, WebList, Dialog, Window and Browser etc…

To Register a Function, foremost define a Function and mark Register User Function declaration at the end of Function Library or in test script. You can Register a New Method for a Test Object Class or Use an Existing Method Name to take priority over the existing Functionality of the specified Method.

If the Function is defined and it is not registered, it operate as a Global Function, you can monitor all your defined functions in Step Generator (F7) if they are globalized. Once the Function is registered, you can’t see the registered function in Step Generator.

The Register Method applicable only in test Script or in Function Library. QTP clears all Registrations at the beginning of Every Run Session.

Syntax: RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault

Arguments:
ToClass: To which Class you want to register the method.
Method Name: String which you like to see in methods List for that class.
Function Name: The name of the user defined function which you have defined.

Note: The Function should be located in your Action or in a Library file which you have associated to your Test Script.
SetAsDefault: Indicating that the registered function should be used as a default method for test object/not

Examples:
1. The following Example describes how to append a new method to QTP Class

Sub AddNewMethod (Object, ParameterValue)
If Object.Exist Then
Reporter.ReportEvent micPass, "Object Exist", "XXXXXXXXX Object is existed on this Page"
Else
Reporter.ReportEvent micFail, "Object Exist", "XXXXXXXXX Object is existed on this Page"
End If
End Sub

Declaration: RegisterUserFunc "WebEdit", "AddNewMethod","AddNewMethod",True

After finishing the delcaration of Function and its Registration save file as “FileName.vbs” and associate to the test script. You will find the registered new method in list of methods which supports WebEdit Class and displays as

Browser("QTP Descriptive Programs").Page("QTP Descriptive Programs").WebEdit("email").AddNewMethod

2. The Following Example describes how to add new function to an existing QTP Class/ method.

Function MySet (Object, x) [Ex: obj = Browser("MercuryTours").Page("FindFlights").WebEdit("Country")]
Dim y
Y = Object.GetROProperty("value")
Reporter.ReportEvent micDone, "previous value", y
MySet=Object.Set(x)
End Function

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

The behavior of the above function is to capture and report the value of an edit box before the new value is entered. We are registering the above function with existing set method of Test Object WebEdit i.e., modifying the Set Method behavior with newly distinct function.

Note: Once a new method is registered, the method becomes a recognized method to that specific Test Object until you unregister that method. If your method overrides an existing QTP method unregistering that method resets the method to its normal behavior. Unregistering new methods deletes that method from list of methods which supports by the Test Object. To Un-Register a Function make use of the following Syntax.

Syntax: UnRegisterUserFunc TOClass, MethodName
Arguments:
ToClass: To which Class you want to register the method.
Method Name: String which you like to see in methods List for that class.

Example: UnRegisterUserFunc "WebEdit", "Set" 

No comments:

Post a Comment