Understanding RegisterUserFunc Syntax with Example
Source:
http://www.qtp10.com/2009/06/registeruserfunc-statement-in-qtp.html
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
Source:
http://www.automationrepository.com/2011/12/understanding-registeruserfunc-syntax-with-example/
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.
Syntax
RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault
Argument | Type | Description |
TOClass | String | The Object with which you want to register the method. Eg: WebEdit, WebButton etc Any test object class. Note: You cannot register a method for a QuickTest reserved object (such as DataTable, Environment, Reporter, and so forth). |
MethodName | String | The name that you want to use while calling the method. Eg: For a WebButton, it can be fnWebButtonClick 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. My comments: Looks like you function(par) ... here par will be taken from object GetHoverColor = oLink.Object.currentStyle.color
Here GetHoverColor is a function, and the above line calls function and retrieves color
or
what does it do????
|
FunctionName | String | The actual name of the user-defined function, i.e. the name that is used during function definition. 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. |
SetAsDefault | Boolean | Optional. Indicates whether the registered function is used as the default operation for the test object. Default Value: False 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). |
Example:
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.
Note: Here first QTP will run SytemUtil -> Registers the Set method and connects with function Myset -> Browser class line, calls the function Myset -> as Set method is overridden by Myset it takes it parameter x as "Canada", as is called -> y will have initial value and x will have canada(it will set to the field).
Function MySet (obj, x)
dim y
y = obj.GetROProperty("value")
Reporter.ReportEvent micDone, "previous value", y
MySet=obj.Set(x)
End Function
SystemUtil.Run "http://www/mycontactform.com
RegisterUserFunc "WebEdit", "Set", "MySet"
Browser("MercuryTours").Page("FindFlights").WebEdit("Country").Set "Canada"
No comments:
Post a Comment