正文

desprogramming

(2011-06-23 13:35:10) 下一個

Programming in Expert View

Programmatic Descriptions
When QuickTest learns an object in your application, it adds the appropriate test object to the object repository. After the object exists in the object repository, you can add statements in the Expert View to perform additional operations on that object.

You can also instruct QuickTest to perform operations on objects without referring to the object repository or to the object’s name. To do this, you provide QuickTest with a list of properties and values that QuickTest can use to identify the object or objects on which you want to perform an operation.You can also use programmatic descriptions to perform the same operation on several objects with certain identical properties, or to perform an operation on an object whose properties match a description that you determine dynamically during the run session.
In the Run Results, square brackets around a test object name indicate that the test object was created dynamically during the run session using a programmatic description or the ChildObjects method.

Programmatic Description Types
There are two types of programmatic descriptions:
Static. You list the set of properties and values that describe the object directly in a VBScript statement.
Dynamic. You add a collection of properties and values to a Description object, and then enter the Description object name in the statement. Using the Static type to enter programmatic descriptions directly into your statements may be easier for basic object description needs. However, in most cases, using the Dynamic type provides more power, efficiency, and flexibility.

Static Programmatic Descriptions
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 identification property and its value.

Each property:=value pair should be separated by commas and quotation
marks.

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"

Guidelines for Using Static Programmatic Descriptions

Regular Expressions in Programmatic Descriptions
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.

Variables in Programmatic Descriptions
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)

Programmatic Descriptions for Parent Test Objects
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 parent objects in the hierarchy have been specified using programmatic descriptions, QuickTest cannot identify the object.
Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Author").Set "Mark Twain"

Reuse of Static Programmatic Descriptions
If you want to use the same static programmatic description several times in one test or in one function library, you may want to assign the object you create to a variable or use a With statement.

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

Copying Programmatic Description Data from the Object Spy
You can use the Copy Identification Properties to Clipboard option in the Object Spy dialog box to copy all identification properties and values for a selected object to the Windows Clipboard.

Dynamic Programmatic Descriptions
You can use the Description object to return a Properties collection object containing a set of Property objects. A Property object consists of a property name and value. You can then specify the returned Properties collection in place of an object name in a statement.

To create the Properties collection, you enter a Description.Create statement using the following syntax:
Set MyDescription = Description.Create()

After you have created a Properties object (such as MyDescription in the example above), you can enter statements to add, edit, remove, and retrieve properties and values to or from the Properties object during the run session. This enables you to determine which, and how many properties to include in the object description in a dynamic way during the run session.

After you fill the Properties collection with a set of Property objects (properties and values), you can specify the Properties object in place of an object name in a test statement.

For example, instead of entering:
Window("Error").WinButton("text:=OK", "width:=50").Click

you can enter:
Set MyDescription = Description.Create()
MyDescription("text").Value = "OK"
MyDescription("width").Value = 50
Window("Error").WinButton(MyDescription).Click

When working with Properties objects, you can use variable names for the properties or values to generate the object description based on properties and values you retrieve during a run session.

Retrieving Child Objects
You can use the ChildObjects method to retrieve all objects located inside a specified parent object, or only those child objects that fit a certain programmatic description. To retrieve this subset of child objects, you first create a description object, and then you add the set of properties and values that you want your child object collection to match using the Description object.

Set MySubSet=TestObject.ChildObjects(MyDescription)
The statements below instruct QuickTest to select all of the check boxes on the Itinerary Web page:
Set MyDescription = Description.Create()
MyDescription("html tag").Value = "INPUT"
MyDescription("type").Value = "checkbox"
Set Checkboxes =
Browser("Itinerary").Page("Itinerary").ChildObjects(MyDescription)
NoOfChildObjs = Checkboxes.Count
For Counter=0 to NoOfChildObjs-1
Checkboxes(Counter).Set "ON"
Next


Using the Index Property in Programmatic Descriptions
The index property can sometimes be a useful identification property for uniquely identifying an object. The index identification property identifies an object based on the order in which it appears within the source code, where the first occurrence is 0.
Index property values are object-specific. Thus, if you use an index value of 3 to describe a WebEdit test object, QuickTest searches for the fourth WebEdit object in the page.
WebEdit("Name:=UserName", "Index:=0")

Note: If there is only one object, using index=0 will not retrieve it.

Opening and Closing Applications Programmatically
You can run any application from a specified location using a SystemUtil.Run statement. This is especially useful if your test includes more than one application, and you selected the Record and run test on any application check box in the Record and Run Settings dialog box. You can specify an application and pass any supported parameters, or you can specify a file name and the associated application starts with the specified file open.
SystemUtil.Run "C:type.txt", "","",""

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.