Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

RegisterUserFunc adds new methods or overrides existing methods for the test object

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

In the actual process of automatic script development, it is found that the methods provided by QTP are not enough, but fortunately, the extensibility of QTP is very strong, the RegisterUserFunc function

RegisterUserFunc functions can either be user-defined or override existing methods

RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault

Description:

The object for which TOClass wants to register the method

The name of the method that MethodName wants to register, with no spaces

The custom function name in the FunctionName function

Whether SetAsDefault should be registered as the default action of the object. The value is: False, or True---- example 1: add a new method for webedit-

Demand:

1. Add a method for webedit named "NewMethod1"

two。 This method acquires the default value of webedit, and writes the value into reporter.

1. Use vbs to encapsulate a method to get the default value of webedit, and write the value to reporter

two。 Use RegisterUserFunc to register the function in the qtp runtime environment to implement the steps:

1. The following code uses vbs to encapsulate a method to get the default value of webedit and write that value to reporter.

Save the following script as a vbs file, here as test.vbs, in d:\

Sub GetDeafaultValue (objWebEdit)

WebEditDeafaultValue = objWebEdit.GetRoProperty ("default value")

Reporter.ReportEvent micDone, "get the default value of WebEdit", "default value is:" & WebEditDeafaultValue

End Sub2. Load the function test.vbs into the runtime environment of qtp

Loading dynamic loading and static loading. This example adopts dynamic loading method.

The qtp expert attempts to enter the following code on the first line:

Executefile "d:\ test.vbs" 3. Register functions in the qtp runtime environment

On the second line, the qtp expert tries to enter the following code:

RegisterUserFunc "WebEdit", "NewMethod1", "GetDeafaultValue" 4.webedit calls the newly registered NewMethod1 method

Browser ("Baidu, you will know"). Page ("Baidu, you will know"). WebEdit ("wd"). NewMethod1

Open the Baidu home page, follow part 1-4, run the qtp script and check the reporter report that the default value of webedit has been written into the report.

In the above example, the author did not write the relevant examples himself, which is extracted from:

Http://www.51testing.com/?uid-306685-action-viewspace-itemid-829971

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report