Relevant Codes

A Test Development Resource for HP QuickTest Professional.

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

by Anshoo Arora on August 12, 2009

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:

Text Box 1:
  
Text Box 2:
Text Box 3:
  
Text Box 4:


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?

As promised, we must create a simple login process using the concepts we have learned so far in the next article.

Descriptive Programming Series

  1. Descriptive Programming (DP) Concepts – 1
  2. Descriptive Programming (DP) Concepts – 2 {Regular Expressions}
  3. Descriptive Programming (DP) Concepts – 3 {Ordinal Identifiers}
  4. Descriptive Programming (DP) – 4 {Creating a Test Script)

1. Credits go to Harish for finding this error. Thank you Harish!!

If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.

{ 46 comments… read them below or add one }

1 Suni Reddy August 18, 2009 at 11:51 pm

Hi Anshoo,

The decription about Ordinal Identifiers is very simple and Clear.Nicely explained about the basics

Cheers
Suni

Reply

2 Anshoo Arora August 19, 2009 at 6:39 pm

Thank you, Suni!

Reply

3 Kuldeep Tyagi September 1, 2009 at 4:39 am

Thank you very much now first time it si pretty clear to me.

Reply

4 Anshoo Arora September 4, 2009 at 5:20 pm

Thank you, Kuldeep. I’m glad you found this article useful.

Reply

5 Shilap September 15, 2009 at 4:04 am

Hello Anshoo,

Can you please me tell me what does CreationTime:=-1 means[Please note it is -1 and not 1]

Example

var=Browser(CreationTime=-1).Exist

Also, I have noticed that this code will always give a “True” value if only a single browser exists.

Reply

6 Anshoo Arora September 15, 2009 at 7:00 pm

Hi Shilap,

You’re absolutely correct. However, if you tried the same code with 2 or more browsers open, it would always return false. Call it a feature, or a bug from HP/Mercury, but if you have only 1 browser open, regardless of what creationTime you specify, it will always return true.

When there is only 1 open browser, the maximum creationtime is 0, and I think in QTP’s terms, there is no reason to form a collection to determine the correct browser. Notice how creationtime works, though. The first browser has creationtime 0, the second has creationtime of 1, the third has a creationtime of 2, and so on. Now, when there is only 1 browser open, it doesn’t really matter what value of creationtime you supply because a single browser can be a creationtime of -100 and +100. Any value would be correct.

The real concept of CreationTime comes into picture when there are 2 or more browser open. If QTP has a bug there, then that would be a good cause for concern. :)

Anshoo

Reply

7 Bibek Khatiwara October 21, 2009 at 8:02 am

Anshoo u r genius…..My assumption is that you people{Anshoo & Tarun} are putting your extra efforts teaching QTP to the people across the globe.

It is people like you who make our world a better place.

Lots of love & thanks
Bibek Khatiwara

Reply

8 Anshoo Arora October 21, 2009 at 5:25 pm

Wow, Bibek! Thank you for your kind words. I feel really honored. Thanks.

Reply

9 Ragha Sudha February 3, 2010 at 4:19 am

From the above description ,i came to know that is cent percent sure that the object would be identified using Ordinal identifier,but why dont we use the ordinal identifier property to recognize the test objects?
Let me know if anyone knows the answer

Reply

10 Anshoo Arora February 4, 2010 at 7:20 am

Hi Ragha,

The answer is quite simple. Because an Ordinal Identifier is a numeric property, it becomes very complex to know the index of an object each time you run your regression. That’s why, having other properties helps understand which object you’re working with, it helps to troubleshoot easily, and most of all -> it makes your scripts robust.

Consider an example where there are 100 links on a page. Now, each link will have Index ordinal identifier from 0 to 99. Now, each link will have its own ordinal identifier. That’s settled. However, if the position of the link changes, the indexes of all object will also change, causing us to lose the object that we need most. That’s why ordinal identifier are coupled with other properties to identify objects.

Reply

11 Ragha Sudha February 9, 2010 at 1:47 am

Thanks for your reply

Reply

12 Renu Bajaj February 13, 2010 at 8:08 am

Hi Anshoo, can pls tell me how to use file system object in descriptive programming
eg.
I’ve to create a excel file, write some data in that sheet and close it . how can we do this in descriptive proramming?

pls suggest
Renu

Reply

13 Anshoo Arora February 14, 2010 at 2:02 am

Hi Renu,

What you’re referring to is not a Descriptive Programming concept, but VBScript. Below is a simple snippet that can be used to write data to Excel WorkBook:

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.WorkBooks.Open("C:\Test.xls")
Set xlSheet = xlBook.WorkSheets("Sheet1")

'Write "This is a demo" to Row 2, Column 7 of the Sheet
xlSheet.Rows(2).Columns(7).Value = "This is a demo"

xlBook.Save
xlBook.Close
xlApp.Quit

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

Reply

14 Ragha Sudha March 2, 2010 at 2:01 am

Can we implement the same code to wirte in to datatable of QTP

Reply

15 Anshoo Arora March 2, 2010 at 4:27 pm

Code for the DataTable would be different. However, you can write data to Excel and Import the Sheet to the desired DataTable.

Reply

16 Renu Bajaj March 5, 2010 at 12:08 am

Hi Anshoo,

what is Automation testing framework, which framework , we can use in QTP?can you give some description about it?

Thanks
Renu

Reply

17 Anshoo Arora March 5, 2010 at 2:50 pm

Renu,

Following document shows the types of frameworks: http://www.ibm.com/developerworks/rational/library/591.html and all of them can be easily created in QTP.

Reply

18 Harish Behl March 12, 2010 at 4:45 am

Hi Anshoo,

This is the 1st time, I have seen your web site and have been reading your articles since morning
I have n’t even opened any other site since morning.
You are providing a rich knowledge for the begineers and at the advance level too. In small words, GREAT WORK AND KEEP IT UP!!!!

Now one basic question,
I didn’t get the picture what should I choose in between Index and location identifier.
Can you please put some more light on this ?
Thanks,
Harish

Reply

19 Anshoo Arora March 12, 2010 at 10:14 am

Harsh,

Index and Location are both Ordinal Identifiers, they’re both numeric assignments for objects consisting in the AUT.

Index works from left to right, Location works top to down. I use Index 99% of the time when choosing between the two because Location can be a little tricky to work with. I will try to create an HTML example and post it as soon as possible.

Reply

20 Harish Behl March 15, 2010 at 7:38 am

Anshoo,

Thanks for your prompt reply.
What I have understood is Index Property is directly proportionaly to Location property.
So, How index is more stable than location and How does it make difference to us whether it’s assigning numeric value from left to right or Top to botton?

-Harish

Reply

21 Anshoo Arora March 15, 2010 at 12:32 pm

I think an example would definitely be helpful here. If you observe the footer of Relevant Codes, you will see the following headers: TAGS, RECENT COMMENTS, SUBSCRIBE/SOCIAL MEDIA. If I am working with the links under the Tags heading, I will use Index. For Subscribe and Social Media, I will use Location. Technically, I can use either, but generally one is easier to understand than the other.

Reply

22 Balaji April 12, 2010 at 7:09 am

Hi,
I have webtable which size 7 column and 4 rows.
Each row i have set of webelements.
I am using checkpoints for checking whether the webelements are there ?
My problem is that , webelement property of one row is similar to other , so it says multiple objects found with the same property.
could you please tell me whether ordianl identifier can use in the checkpoint?
if so please let me konw?

Reply

23 Sophie April 14, 2010 at 3:22 pm

Hi Anshoo,

Thanks a lot for such a wonderful explanation on DP.

I have small doubt, could you please explain me with an example(real time) – how “CreationTime Ordinal Identifier” are useful.

Thank you,

Sophie

Reply

24 Anshoo Arora April 14, 2010 at 3:33 pm

Consider the following scenario that opens 2 identical browsers:

SystemUtil.Run "iexplore.exe", "http://google.com"
SystemUtil.Run "iexplore.exe", "http://google.com"

How will you work with the first open browser? Here, creationTIme of 0 will be used. How will you work with the second open browser? Here, creationTime of 1 will be used.

In other words, each browser has a numerical identity defined in terms of CreationTime and it always starts with 0. The first browser will have CreationTime of 0, second will have CreationTime of 1, third will have CreationTime of 2 and so on.

Reply

25 Sophie April 14, 2010 at 3:43 pm

Thanks a lot Anshoo for such a quick reply, got it now. Thanks once again

Could you please suggest me some other stuff, i am in the learning phase of QTP, done with classroom course, however still need to work on to understand real environment.

Reply

26 Dennis April 19, 2010 at 2:43 am

Hi, Anshoo,

Thank you for this so thorough guidelines for DP.

I have one requirement which need to complete by DP, maybe also scripting in QTP. Could you kindly help me to investigate in it?

The example is

I want to get the source code of one web page, and then I need to verify the META tag if it is existed.
E.g.,

I need to verify whether the value of content is “text/html;charset=UTF-8″.
I need to verify whether the value of http-equiv is “Content-Type”.

I don’t plan to use this method: Right Click -> View Source -> Get the source code.

How can I get it by DP or scripting in QTP? In other words, how can I get an object which hide in the source code? Maybe I got the misunderstanding of the definition for “Object” in QTP.

Could you advise?

Thank you.

Regards,
Dennis

Reply

27 anshooarora April 19, 2010 at 5:20 am

Dennis,

This can be done through HTML DOM:

Set oRegExp = New RegExp
oRegExp.IgnoreCase = True
oRegExp.Global = False
oRegExp.Pattern = "content=.text/html;.*charset=UTF-8."

sOuterHtml = Browser("").Page("").Object.documentElement.outerHtml

Set oMatches = oRegExp.Execute(sOuterHtml)

If oMatches.Count > 0 Then
	Reporter.ReportEvent micPass, "Content-Type", oMatches(0)
End If

oRegExp.Pattern = ".*http-equiv.*Content-Type.*"

Set oMatches = oRegExp.Execute(sOuterHtml)

If oMatches.Count > 0 Then
	Reporter.ReportEvent micPass, "http-equiv", oMatches(0)
End If

Set oMatches = Nothing
Set oRegExp = Nothing

I have used the RegExp object above, but it can also be done through InStr, Left/Right/Mid.

Reply

28 Dennis April 19, 2010 at 6:07 am

Hi, Anshoo,

Yeah, that’s a good solution for this. Thank you for your quick response.
A quick question for your information:

Do you have any concerns about the performance of this method?

Regards,
Dennis

Reply

29 Anshoo Arora April 19, 2010 at 10:33 pm

It worked quite well for me Dennis. On which lines do you see a drop in performance? We can surely fix it! :)

Reply

30 Dennis April 22, 2010 at 8:22 am

Hi,

Firstly, sorry for the delay of this reply.

Yeah, in practice, I’ve tried to do some stress testing in such larger HTML file by this code even use this code in several iterations , but fortunately, it can work well.

Thanks again for your kindness and your help.

Regards,
Dennis

Reply

31 Anshoo Arora April 25, 2010 at 3:14 pm

:)

Reply

32 Dennis April 26, 2010 at 4:50 am

Hi, Anshoo,

I have read this article again today, and I found another question.

How can I simply use the “Object Spy” tool for retrieving the “Location” and “Index”? Is that possible? Do I need to add some customerized properties in “Object Identification”?

In other words, how could I explicitly retrieve the value of “Location” and “Index” ?

Do you have any good idea?

Thank you in advance.

Regards,
Dennis

Reply

33 Anshoo Arora April 28, 2010 at 2:43 am

Hi Dennis,

The Object Spy cannot retrieve either Location or Index identifiers (or CreationTime for Browser) as these are all run-time properties and cannot be determined at design time.

Using QTP methods, the only possible way is to do this through ChildObjects.

Reply

34 Dennis April 30, 2010 at 9:24 pm

Hi, Anshoo,

Thank you very much. Yeah, I concur with you, maybe that is the only way what I can get it done. Hope it can be implemented by QTP11 :), since I think these properties is very useful.

Regards,
Dennis

Reply

35 Anshoo Arora May 2, 2010 at 12:41 pm

QTP 11 Beta 1 is being released tomorrow *fingers crossed*. There have been several improvements/enhancements, but we’ll only know for sure when we try :)

Reply

36 Dennis May 7, 2010 at 2:28 am

yeah, aha. Perhaps, we cannot see beta version so quickly, and I think alpha version will coming soon. :D

Reply

37 Manish Bansal June 27, 2010 at 1:47 pm

any URL to give a test ?

Reply

38 Harish May 7, 2010 at 2:46 am

QuickTest can assign a value to the test object’s Location property to uniquely identify the object. The first occurrence of the object is 0. Values are assigned in columns from top to bottom, and left to right. Location property values are object-specific.

QuickTest can assign a value to the test object’s Index property to uniquely identify the object. The first occurrence of the object is 0. The value is based on the order in which the object appears within the source code. Index property values are object-specific.

(Reference: Mercury QuickTest Professional User’s Guide > Working with Advanced Testing Features > Configuring Object Identification > Understanding the Object Identification Dialog Box > Selecting an Ordinal Identifier)

Reply

39 Yogesh Basediya May 28, 2010 at 8:33 am

Hi Anshoo,

Your are doing great job buddy! I really appreciate it..
I have a question that is out of this box.. but still i have to ask.
I am using Excel sheet in place of Access DB for Input source. and That excel file i m using as a Database (Not as a Excel sheet). But as we know that we can not delete rows from Excel tables.. and in the same time i m not able to set Null value for those particular fields too. So could you please tell me what else i could do just to overcome this problem?

Reply

40 Anshoo Arora June 22, 2010 at 12:48 pm

Hi Yogesh,

Please see this article: http://techsupt.winbatch.com/ts/T000001033005F50.html

I hope it will be helpful to you :)

Reply

41 Gaurav July 28, 2010 at 5:12 am

Amazing the best source to learn QTP……Great work Anshooo

Reply

42 Setty July 28, 2010 at 5:23 pm

Does anyone know if QTP 11 supports Safari browser or MAC OS?

Reply

43 Dennis July 30, 2010 at 3:04 am

Sorry, this is the confidential information of HP SW Lab. :)

Reply

44 Anuj Garg August 7, 2010 at 12:24 pm

Hi Anshoo

The article is very useful and cleared a lot of concepts of mine. But I have a problem:
I have a table/sheet with 20 records having the field names – id, name, address. I have to fetch the 10th record that will contain only ‘name’ field. How can we do it in DP? Please suggest.

TIA
Anuj Garg

Reply

45 Anshoo Arora August 8, 2010 at 7:51 pm

Anuj,

What is the technology of your application?

Reply

46 Anuj Garg August 13, 2010 at 1:52 pm

The app is built on ASP.net with C#.

Reply

Leave a Comment

{ 5 trackbacks }

Previous post:

Next post: