Descriptive Programming (DP) Concepts – 3 (Ordinal Identifiers)

This is the third article in the Descriptive Programming series, and will outline the concepts of Ordinal Identifiers used in QTP. We will also create a simple test module (step by step) for a login process using only Descriptive Programming (DP).

Ordinal Identifiers – What are they?

Let me quote QTP Reference here:

An ordinal identifier assigns a numerical value to a test object that indicates its order or location relative to other objects with an otherwise identical description (objects that have the same values for all properties). This ordered value provides a backup mechanism that enables QuickTest to create a unique description to recognize an object when the defined properties are not sufficient to do so.

Let’s break the above definition from Mercury/HP into several parts to clarify the concept.

An ordinal identifier assigns a numerical value to a test object

From the quote above, we can conclude that an ordinal identifier is a numerical entity. In other words, its simply a number that is assigned to a test object.

that indicates its order or location relative to other objects with an otherwise identical description (objects that have the same values for all properties)

This means, an Ordinal Identifier works quite differently in relation to the properties we learned in the 1st part of this series. This identifier, or a property if you will, works according to the order or location of test objects. Objects’ order and location are unique characteristics. For example, in a coordinate system, generally only a single object exists on a given ‘x,y’ coordinate. Thus, an ordinal identifier will always be unique. Index defines the order, and location defines location.

This ordered value provides a backup mechanism that enables QuickTest to create a unique description to recognize an object when the defined properties are not sufficient to do so.

The quote above is a good way to conclude this concept of Ordinal Identifiers in QTP. Since it is always unique for an object, it can become extremely useful including these with objects’ mandatory and assisstive properties to prevent falling into object recognition problems. The 3 types of ordinal identifiers are: Location, Index and CreationTime (browser only).

Location Ordinal Identifier

Let’s use an example to understand how the Location Identifier works. Consider the 4 WebEdits below:

All the edits above have exactly the same properties. This property works vertically, from top to bottom, and left to right. Thus, ‘Text Box 1‘ will have a location value of 0, ‘Text Box 3‘ will have 1, ‘Text Box 2‘ will have 2, and ‘Text Box 4‘ will have 3. Note that VBScript is zero based, so the location property would start at 0. This can be verified by running the following statements:

'Text Box 1
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest","location:=0").Set "1"
 
'Text Box 3
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest","location:=1").Set "2"
 
'Text Box 2
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest","location:=2").Set "3"
 
'Text Box 4
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest","location:=3").Set "4"
Text Box 1: location=0
Text Box 2: location=2
Text Box 3: location=1
Text Box 4: location=3

Index Ordinal Identifier

Index is quite similar to location, but it works pertaining to appearance of objects in the source code1. An object appearing prior in the source code will have a smaller Index value as compared to another object that comes later in the source. Thus, for the same group of edit boxes above: ‘Text Box 1′ will have an index of 0, ‘Text Box 2′ will have 1, ‘Text Box 3′ will have 2 and ‘Text Box 4′ will have 3. Let’s test our statements:

'Text Box 1
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest", "index:=0").Set "1"
 
'Text Box 2
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest", "index:=1").Set "2"
 
'Text Box 3
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest", "index:=2").Set "3"
 
'Text Box 4
Browser("title:=.*Descriptive.*").Page("micclass:=Page").WebEdit("name:=dpTest", "index:=3").Set "4"
Text Box 1: index=0
Text Box 2: index=1
Text Box 3: index=2
Text Box 4: index=3

That was quite easy, wasn’t it? Now, let’s move on to CreationTime, which is an ordinal identifier strictly reserved for the browser object.

CreationTime Ordinal Identifier

Again, let’s use the description given by HP/Mercury in QTP’s helpfile:

If there are several open browsers, the one with the lowest CreationTime is the first one that was opened and the one with the highest CreationTime is the last one that was opened.

That means, the first browser you open will have a creationtime of 0. The second browser will have a creationtime of 1. The third browser will have a creationtime of 2 and so on.

SystemUtil.Run "iexplore.exe", "http://www.HP.com"               'CreationTime 0
SystemUtil.Run "iexplore.exe", "http://www.AdvancedQTP.com"      'CreationTime 1
SystemUtil.Run "iexplore.exe", "http://www.LinkedIn.com"         'CreationTime 2

Browser( "creationtime:=" ).Highlight     'Highlight HP.com
Browser( "creationtime:=1" ).Highlight    'Highlight AdvancedQTP.com
Browser( "creationtime:=2" ).Highlight    'Highlight LinkedIn.com

When you run the above code in QTP, you will find that the first browser QTP highlights on is HP.com, the second is AdvancedQTP.com and the third is LinkedIn.com. Even this is quite simple, isn’t it?

Leave a Comment

Scroll to Top