Thursday 9 May 2013

Descriptive Programming and ChildObjects


Descriptive Programming


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. During the run session, QuickTest finds the object in the object repository based on its name and parent objects, and uses the stored test object description for that test object to identify the object in your application.

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.

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 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.

There are two types of programmatic descriptions:

Static- In Static descriptions, list the set of properties and values that describe the object directly in a Vb Script statement. 

Dynamic- In Dynamic descriptions  one has to 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.

For Example-
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"

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"

In this case, 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.

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. (Each property object contains a property name and value pair).

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

one can enter:

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


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.

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.

After you build a description in your description object, use the following syntax to retrieve child objects that match the description:
Set MySubSet=TestObject.ChildObjects(MyDescription)

Example
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


4 comments: