Entering Programmatic Descriptions Directly into Statements

Entering Programmatic Descriptions Directly into Statements

You can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object's name.

The general syntax is:

TestObject("PropertyName1:=PropertyValue1", "..." , "PropertyNameX:=PropertyValueX")

TestObject. The test object class.

PropertyName:=PropertyValue. The test object property and its value. Each property:=value pair should be separated by commas and quotation marks.

Note that you can enter a variable name as the property value if you want to find an object based on property values you retrieve during a run session. For example:

MyVar="some text string"

Browser("Hello").Page("Hello").Webtable("table").Webedit("name:=" & MyVar)

Note: QuickTest evaluates all property values in programmatic descriptions as regular expressions. Therefore, if you want to enter a value that contains a special regular expression character (such as *, ?, or +), use the \ (backslash) character to instruct QuickTest to treat the special characters as literal characters.

The statement below specifies a WebEdit test object in the Mercury Tours page with the Name author and an index of 3. During the run session, QuickTest finds the WebEdit object with matching property values and enters the text Mark Twain.

Browser("Mercury Tours").Page("Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain"

Notes: When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions from that point onward within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have been specified using programmatic descriptions, QuickTest cannot identify the object.

For example, you can use the following statement since it uses programmatic descriptions throughout the entire test object hierarchy:

Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain"

You can also use the statement below, since it uses programmatic descriptions from a certain point in the description (starting from the Page object description):

Browser("Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain"

However, you cannot use the following statement, since it uses programmatic descriptions for the Browser and Page objects but then attempts to use an object repository name for the WebEdit test object:

Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Author").Set "Mark Twain"

QuickTest tries to locate the WebEdit object based on its name, but cannot locate it in the repository because the parent objects were specified using programmatic descriptions.

For more information on working with test objects, see Working with Objects.

If you want to use the same programmatic description several times in a function library, you may want to assign the object you create to a variable.

For example, instead of entering:

Window("Text:=Myfile.txt - Notepad").Move 50, 50

Window("Text:=Myfile.txt - Notepad").WinEdit("AttachedText:=Find what:").Set "hello"

Window("Text:=Myfile.txt - Notepad").WinButton("Caption:=Find next").Click

You can enter:

Set MyWin = Window("Text:=Myfile.txt - Notepad")

MyWin.Move 50, 50

MyWin.WinEdit("AttachedText:=Find what:").Set "hello"

MyWin.WinButton("Caption:=Find next").Click 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16792402/viewspace-567242/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/16792402/viewspace-567242/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值