Professional Documents
Culture Documents
You can also instruct QTP to perform methods on objects without referring to the Object
Repository, without referring to the object’s logical name. To do this, you provide QTP with
a list of properties and values that QTP can use to identify the object or objects on which
you want to perform a method.
Such a programmatic description can be very useful if you want to perform an operation on
an object that is not stored in the object repository. You can also use programmatic
descriptions in order to perform the same operation on several objects with certain identical
properties, or in order to perform an operation on an object whose properties match a
description that you determine dynamically during the test run.
1) You can either list the set of properties and values that describe the object directly in a
test statement,
2) or you can add a collection of properties and values to a description object, and then
enter the description object name in the statement.
You can describe an object directly in a test statement by specifying property:=value pairs
describing the object instead of specifying an object’s logical name.
For Example:
If you want to use the same programmatic description several times in one test, you may
want to assign the object you create to a variable.
For Example:
MyWin.Move 50, 50
Once 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 test run. This enables you to determine which, and
how many properties to include in the object description in a dynamic way during the test
run.
Once you have filled the Properties collection with a set of Property objects (properties and
values), you can specify the Properties object in place of a logical name in a test statement.
MyDescription("text").Value = "OK"
MyDescription("width").Value = 50
Window("Error").WinButton(MyDescription).Click
Retrieving ChildObjects:
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. In order to
retrieve this subset of child objects, you first create a description object and add the set of
properties and values that you want your child object collection to match using the
Description object.
Note: You must use the Description object to create the programmatic description for the
ChildObjects description argument. You cannot enter the programmatic description directly
into the argument using the property:=value syntax.
Once you have "built" a description in your description object, use the following
syntax to retrieve child objects that match the description:
Set MySubSet=TestObject.ChildObjects(MyDescription)
For example, the statements below instruct QTP to select all of the check boxes on
the Itinerary Web page:
Set MyDescription = Description.Create()
MyDescription("type").Value = "checkbox"
NoOfChildObjs = Checkboxes.Count
Checkboxes(Counter).Set "ON"
Next
or
WebObjDesc("Name").Value = "UserName"
WebObjDesc("Index").Value = "0"
QTP clicks on the first Web object in the Mercury Tours page with the name UserName.
The index property can sometimes be a useful test object property for uniquely identifying
an object. The index test object property identifies an object based on the order in which it
appears within the source code, where the first occurrence is 0.
Note that index property values are object-specific. Thus, if you use an index value of 3 to
describe a WebEdit test object, QTP searches for the fourth WebEdit object in the page.
If you use an index value of 3 to describe a WebElement object, however, QTP searches for
the fourth Web object on the page regardless of the type, because the WebElement object
applies to all Web objects.
For example, suppose you have a page with the following objects:
The description below refers to the third item in the list above, as it is the first WebEdit
object on the page with the name UserName.
WebEdit("Name:=UserName", "Index:=0")
The following description, however, refers to the second item in the list above, as that is the
first object of any type (WebElement) with the name UserName.
WebElement("Name:=UserName", "Index:=0")
You can use the Object property to access the native properties of any run-time object. For
example, you can retrieve the current value of the ActiveX calendar’s internal Day property
as follows:
Dim MyDay
Set MyDay=Browser("index").Page("Untitled").ActiveX("MSCAL.Calendar.7").Object.Day
You can use the Object property to activate the internal methods of any run-time object.
For example, you can activate the edit box’s native focus method as follows:
Dim MyWebEdit
MyWebEdit.focus