Relevant Codes

A Test Development Resource for HP QuickTest Professional.

Descriptive Programming (DP) Concepts – 1

August 10, 2009 · 43 comments

Introduction
Descriptive programming has become the technique of choice for many QTP test developers. We can talk about its advantages and disadvantages all day, but here, we’ll only discuss the concepts and come up with our own idea of what it does better, and what it doesn’t :). This is going to be a very quick refresher before we move on to its everyday application by completing an end-to-end testcase.

The idea behind descriptive programming is for automation developers to instruct QTP which properties they would like to use to identify an object, instead of having QTP to choose them itself. If done correctly, this can help create robustness in scripts, ultimately requiring less maintenance-time and more development time.

Let’s begin.

But wait, before we really begin, we must understand QTP’s Object Spy. It is an inbuilt tool that enlists all of the test-object and runtime-object properties. These properties are different for different types for objects. For example, an image has a property called ‘file name’ whereas a listbox doesn’t. Instead, a listbox has a special ‘all items’ property whereas the image doesn’t. This discussion will be limited to the usage test-object properties to identify objects. Below are 2 snapshots of the Object Spy:

Object Spy Icon

Object Spy Icon

Object Spy Window

Object Spy Window

Now, let’s open www.Google.com and use the object spy to retrieve all properties of the search box:

Object Spy: WebEdit Properties

Object Spy: WebEdit Properties

Notice the image above. The editbox has a HTML TAG property with its corresponding value ‘INPUT’. This means, the editbox takes some input from the user – which is true because we do set some value in it! It also has a ‘MAX LENGTH’ property, with a value of ‘2048′. This means, you can enter a maximum of 2048 characters in it (the best source to see all of the Test-Object properties of objects is the QTP help itself). Below you will see an editBox which can contain a maximum of 9 characters:

Test maxLength:

You can really use all these properties to identify this editbox, but, do we really need to use all of them? No. That is the most important idea behind descriptive programming – we only use what we need. Below is how we write descriptions for objects:

ObjectClassName("property:=value", "property:=value")
 
' ofcourse we're not limited to only 2 properties. We can write more:
ObjectClassName("property:=value", "property:=value", "property:=value")

Above, ObjectClassName (in Web applications) can be Browser, Page, Frame, WebEdit, Image etc. Properties come from the left column the ObjectSpy column whereas values are in the right column. We can include as many properties as we want, but in reality, we only need to add a few to uniquely identify the object. Knowing which properties should suffice to uniquely identify can object will come from experience and practice. Below is a description I created for this editbox (WebEdit):

'ObjectClassName( "property1:=value1", "property2:=value2" )
WebEdit( "name:=q", "html tag:=INPUT" )

I already mentioned the HTML TAG and its value INPUT above. We’ve also added a new property/value here: ‘name:=q’. Is this enough to uniquely identify the object? Yes. But is it enough to make our script work? No, sadly its not.. and that is because, we haven’t yet created descriptions for its parent objects: Browser & Page. Below are the snapshots of the spied browser and page objects:

Object Spy: Browser Properties

Object Spy: Browser Properties

Object Spy: Page Properties

Object Spy: Page Properties

Browser description:

'ObjectClassName( "property1:=value1" )
Browser( "title:=Google" )

Page description:

Page( "title:=Google" )

Now, we will connect all these descriptions and form a hierarchical tree:

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","html tag:=INPUT")

You might wonder why I have omitted the WebTable below the Page and above the WebEdit object. In practice, we can also skip the Page object to identify the WebEdit. But, why did I skip the WebTable after all!? When you experiment more with DP, you will discover that some objects are embedded in many WebTables, and it will become cumbersome if we were to include all WebTables in the hierarchy to get to the object of interest (thanks to the person who thought that will be a terrible idea!). Example of the previously mentioned scenario:

Object Spy: Multiple WebTables

Object Spy: Multiple WebTables

To complete the statement above, we will add an event. In QTP, events can be described as actions on target objects. For example, a WebEdit has a ‘Set’ event. we use the ‘Set’ method of a WebEdit to set a value:

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","html tag:=INPUT").Set "DP"

Set is a QTP event to put in a value in the edit box. Different objects have different events. For example: an Image has a ‘Click’ event associated with it.

This, we did without using Object Repository. The same concept applies to all objects regardless of what your environment is. We perform actions on child objects by accessing their object hierarchies. Let’s complete the above example by searching for our keywords (use the spy again on the search button):

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q", "html tag:=INPUT").Set "DP"
Browser("title:=Google").Page("title:=Google").WebButton("name:=Google Search").Click

This is how the same code will look like if we had recorded this process:

Browser("Google").Page("Google").WebEdit("q").Set "DP is great"
Browser("Google").Page("Google").WebButton("Google Search").Click

These properties are now stored in QTP’s Object Repository (OR). There is another way we can create object descriptions, which is done by setting a reference:

' Creating Browser description
' "title:=Google"
Set oGoogBrowser = Description.Create
oGoogBrowser( "title" ).value = "Google"
 
' Creating Page description
' "title:=Google"
Set oGoogPage = Description.Create
oGoogPage( "title" ).Value = "Google"
 
'* Creating WebEdit description
' "html tag:=INPUt", "name:=q"
Set oGoogWebEdit = Description.Create
oGoogWebEdit( "html tag" ).Value = "INPUT"
oGoogWebEdit( "name" ).Value = "q"

Once we do the above, we can use this descriptions in our script:

Browser(oGoogBrowser).Page(oGoogPage).WebEdit(oGoogWebEdit).Set "DP is great"

The only time I use this technique is to retrive object collections through ChildObjects (we will discuss this in the coming tutorials).

Let’s do another example. Again, we will use Google, but instead of setting a value, we will click an object. You can choose any Link on the page; I chose the link ‘Images’:

Object Spy: Google Images Link

Object Spy: Google Images Link

'ClassName("property:=value").ClassName("propert1:=value").ClassName("property:=value").Event
Browser("title:=Google").Page("title:=Google").Link("innertext:=Images", "html tag:=A").Click

This time, instead of ‘Set’ we used ‘Click’. Following is a list of events we perform on Web objects:

Object Event
Image Click
WebButton Click
WebCheckBox Set
WebEdit Set
WebElement Click
WebList Select
WebRadioGroup Select



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)

References

  1. QuickTest Professional Help

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.

{ 6 trackbacks }

QTP: Descriptive Programming Concepts - 1 (by Anshoo Arora …
August 29, 2009 at 1:22 am
Descriptive Programming (DP) Concepts - 3 {Ordinal Identifiers & Demo} (by Anshoo Arora) | Relevant Codes
September 4, 2009 at 6:41 pm
Descriptive Programming (DP) Concepts – 2 {Regular Expressions} | Relevant Codes
September 4, 2009 at 6:42 pm
Descriptive Programming (DP) - 4 {Creating a Test Script) (by Anshoo Arora) | Relevant Codes
September 5, 2009 at 3:12 pm
QTP: Understanding the Description Object (Description.Create) by Anshoo Arora | Relevant Codes by Anshoo Arora
September 8, 2009 at 6:09 pm
QuickTest's Custom CheckPoints and Beyond | Relevant Codes by Anshoo Arora
October 21, 2009 at 5:42 pm

{ 37 comments… read them below or add one }

1 Gautami August 11, 2009 at 9:21 pm

Your introduction to Descriptive Programming is awesome! It is concise, well-explained and I found it really helpful.

Thanks

Reply

2 Anshoo Arora August 11, 2009 at 9:21 pm

Thanks! :)

Reply

3 Shivani August 24, 2009 at 7:11 am

Hello Anshoo,

You seems to be another expert in the field of QTP and I am deeply impressed by your posts which truly represents your vast experience along with your expertise. I have a question for your that may sound silly to you( as I am a QTP beginner). Still m taking courage to ask: I read in the QTP help file that :

###########################################################
Note for users of previous QuickTest versions: When you open a test that
was created using a version of QuickTest earlier than version 9.1, you are
asked whether you want to convert it or view it in read-only format.
Whether you choose to open it in read-only format or convert it, the object
repositories are associated to the test as follows:
➤ If the test previously used per-action repositories, the objects in each
per-action repository are transferred to the local object repository of each
action in the test.
➤ If the test previously used a shared object repository, the same shared
object repository is associated with each of the actions in the test, and
the local object repository is empty.
#############################################################

I have a doubt in the second point. What if my test created in a previous version (say QTP 9.0 ) contains both Local and Shared OR. So as per the second point will be Local OR will get deleted as it is saying the local OR is empty??

Regards,
Shivani

Reply

4 Anshoo Arora August 24, 2009 at 4:55 pm

Hi Shivani,

If your test contains both Shared and Local Object Repositories, then:

1. Your Local Repositories will be transferred to the local repository of each action in the test, as mentioned in the first bullet point.
2. Your Shared Repositories will be associated with the same test, but since you also have Local Repositories, in your case, your Local Repositories won’t be empty. They will contain information from #1 above.

I hope this will clarify your doubt. :)

-Anshoo

Reply

5 Shivani August 24, 2009 at 11:11 pm

Hi Anshoo,

Doubt cleared :)

Reply

6 Shivani August 25, 2009 at 12:04 am

One more doubt in your article..

You have mentioned: We can skip the Page object..So which is the best coding method

Browser().Page().WebEdit().Set ""

OR

Browser().WebEdit().Set ""

Is there any particular case where we can say First method is the best one and also the case where we can say second method is the best one?

Reply

7 Anshoo Arora August 25, 2009 at 9:52 pm

Excellent question, Shivani! You’re the first one to catch that.

.. and to be honest with you, its one that’s quite hard to answer. Performance wise, there is a negligible difference between the 2 techniques. Usage wise, they both work quite well and are equally readable. That is, the reader can always make out what the script is doing between both methods.

Therefore, in the end, it bottles down to personal preference. I use the 2nd one in your post 90% of the time, and I have not yet come across a situation when it failed to work. But, please note that when you are using ChildObjects to retrieve an object collection, you must specify the complete hierarchy:

Set colLinks = Browser( "" ).Page( "" ).ChildObjects(oLink)

Other than that, I guess its just a personal preference. If you browse other QTP sites/forums, you will see the first approach used the most. I know this answer isn’t satisfying, but I hope you will be able to choose one that you would like to use extensively. :)

Reply

8 Shivani August 26, 2009 at 7:17 am

Thanx for the explanation..Your answer is really satisfying for me.. Thank you so much Anshoo..

Reply

9 vikas August 31, 2009 at 2:24 am

Hi Anshoo,
Your knowledge and the way , you explained the things, just great. really really fantastic…
There are so many sites and blogs , explaining all these kind of QTP stuffs, but your’s I found different.

Reply

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

Thank you, Vikas. I’m very glad that you found it useful. Likewise, if you saw some areas needing improvement, please do let me know. :)

Thanks- Anshoo

Reply

11 Pooja September 20, 2009 at 5:57 am

Hi Anshoo ….

I read ur articles and codes which u gave , they are really very good …. it seems that ur expert in QTP….
I’m learning QTP these days … i hope u can provide help on that.

Thanks

Reply

12 Anshoo Arora September 20, 2009 at 4:04 pm

Thanks! :)

Please feel free to ask any questions that you may have. I will try my best to help you.

Reply

13 Kiran September 20, 2009 at 12:55 pm

Greetings !
I appreciate the work being done by you for the QuickTest newbie’s.Anshoo,as a member of AdvancedQTP forum, your solutions for the queries are very simple and easily understandable even for the newcomers. Great Job!
Please make me clear with the Recovery Scenario.
As every tester wants the script to be continued after particular recovery event has been handled then why don’t they use “If then else” instead of a calling a .vbs or instead of using a recovery manager.
When ,How and Where should i use recovery scenario.

Have a nice time
Kiran

Reply

14 Anshoo Arora September 20, 2009 at 4:12 pm

When using Conditional Statements, you know that might happen here, and create conditions to tackle expected behavior of the application. For example, you may create the following Conditional Statement:

If Browser("").Page("").WebEdit("").Exist(0) Then
    Reporter.ReportEvent micPass, "WebEdit", "The WebEdit was found!"
Else
    Reporter.ReportEvent micFail, "WebEdit", "The WebEdit was not found!"
End If

Above, you know that there can be only 2 conditions for the WebEdit – that it exists, or it does not.

The same cannot be said when using Recovery Scenario. The reason why they’re called Recovery Scenarios is that, they help us Recover from something we do not expect. For example, you’re running a script and IE crashes. What do you do now? If you have a Click event right after IE shuts, QTP will throw a run-time error and your script will stop. This is where you may want to use a Recovery Scenario because you’re trying to handle an error that you would not normally expect.

The above example may be an extreme case, but I hope it clarifies the main difference between the two. One is where you expect what might happen, whereas, the other helps you overcome an issue that you would not normally expect to occur during run-time.

I hope this helps. If you’re still unclear, or have another question after reading my reply above, please feel free to ask! :)

Anshoo

Reply

15 Kiran September 20, 2009 at 9:34 pm

The reason why i said so is that we never had a situation other than handling the pop-ups.Let me assume that IE crashes while performing a DD testing.Suppose IE crashes at TestIteration no 50 and still 40 to finish.Will the script execute from 51 or 1? How to overcome such issues?
And also as we are unsure where exactly this might occur,we need to instruct the QuickTest to check on every line in the script for recovery which degrades the Tool performance.Doesn’t it?
I am elaborating this topic so that i can get a clear idea about recovery scenario. Thanks for the reply.

Kiran

Reply

16 Anshoo Arora September 21, 2009 at 7:46 pm

Hi Kiran,

I appreciate your interest in learning more, and making your concepts clear.

Will the script execute from 51 or 1? How to overcome such issues?

In such a case, you have the following 6 possible steps to choose from:

  1. Repeat current step and continue
  2. Proceed to next step
  3. Proceed to next action or component iteration
  4. Proceed to next test iteration
  5. Restart current test run
  6. Stop the test run

In other words, you can choose any of the 6 possible choices above. If you would like to exit, then you can do that as well.

we need to instruct the QuickTest to check on every line in the script for recovery which degrades the Tool performance.Doesn’t it?

Technically, we don’t instruct QTP how to use the Recovery Scenario, we just tell it what should trigger it. QTP finds if an application state matches with what we have in our scenario and activates the trigger.

As for performance, it may impact it, but by only a little, I hope. They’re triggered only when QuickTest encounters a particular application behavior. You may be correct in saying that QTP may check after each executed line whether to trigger the Recover Scenario or not. However, I’m not too sure about this. Possibly someone at HP can answer this for us.

I am elaborating this topic so that i can get a clear idea about recovery scenario.

That’s great, Kiran. I feel I should learn more about Recovery Scenarios myself. Clearly, my knowledge on this subject is not vast enough to answer your questions accurately. This is going to be an action item, then!

Reply

17 Kiran September 22, 2009 at 9:53 pm

Hi Anshoo,
In search of Recovery Scenario i have gone through many forums and blogs but could only find the all-known pop up error handling.And also i found all the forums and blogs have almost same topics and examples about the QTP.
If you can provide video tutorials,with real time issues, that will be a great help for the visitors.Thanks for the reply!
I haven’t tried it yet but will let you know the outcome once done.

Have a nice time
Kiran

Reply

18 Anshoo Arora September 22, 2009 at 10:18 pm

Sure, Kiran. I will try my best to help you.

Reply

19 Anshoo Arora October 23, 2009 at 10:40 pm

Hi Kiran,

An article on Recovery Scenarios has been published here a few days ago. I thought you might be interested.

I was not able to record a video, but I have included several snapshots to try to cover up the visual component. Hope you like it. :)

Reply

20 Pragya October 27, 2009 at 12:16 am

Hello Anshoo

M here to trouble you again with a very annoying query of mine.

See this website :–> http://in.buzz.yahoo.com/ In this website, you will see a Yahoo logo image at the top. I am not able to click this logo using descriptive Programming though I am able to do so with the help of Object Repository. I tried various combinations but nothing worked. I am using QTP 9.2 with IE 7.

This is the code I tried:

Browser(“micclass:=Browser”).Page(“micclass:=Page”).Image(“html tag:=IMG”,”image type:=Image Link”,”alt:=Yahoo! Buzz India (TM)”).Click

It didnt worked. When I record on this image, the learned/mandatory properties are these three only . I am really confused what to do…

Reply

21 Anshoo Arora October 27, 2009 at 8:40 am

HI Pragya,

You can try any of the solutions below:

Browser("title:=.*Buzzing.*").Image("file name:=buzz_logo_.*").Highlight
Browser("title:=.*Buzzing.*").Image("file name:=buzz_logo_tm_in_033109.gif").Highlight
Browser("title:=.*Buzzing.*").Image("alt:=Yahoo! Buzz India \(TM\)").Highlight
Browser("title:=.*Buzzing.*").Image("name:=Image", "index:=0").Highlight

I hope this helps :)

Reply

22 Satishkumar Dega October 29, 2009 at 12:22 am

Hi Anshoo,

I am the beginer of QTP I want to learn Regular Expression conpet and Parameterization concept in QTP.
What is the use of both things can u explain the things with good real time example.I need those things please help me on this.

Reply

23 Anshoo Arora October 29, 2009 at 10:15 am

Hi Satish,

Please see my other comment here about Regular Expressions. I am currently working on an article on Parameterization, and hopefully I will try to have it released soon.

In the meantime, to give you a brief overview, Parameterization is a technique in which you replace an actual value or an entity with a variable. That variable in turn, retrieves values from a data-pool and uses those values to drive the automation. For example, consider the following statement:

Browser("Google").Page("Google").WebEdit("Search").Set "Descriptive Programming"

We can replace the “Descriptive Programming” bit with a Parameter:

Browser("Google").Page("Google").WebEdit("Search").Set sText

Now, in our table, we can have the following structure:

Search Text
Descriptive Programming
Regular Expressions

Therefore, the first time our code executed, sText will take “Descriptive Progamming” as input and write that value to our Search Box. In the 2nd iteration, Regular Expressions will be written.

I hope this helps..

Reply

24 Stefan November 30, 2009 at 5:47 am

Hello Anshoo,

great site and very accurately written topics and answers on questions!

Can you please help me on something… I’m trying to work out how to refer to a webelement in a webtable by DP and a parameter as innerhtml. Maybe you have already described how to do this, but I couldn’t find it here (if so post a link, please).

I want to use something as [...] .WebElement(“innertext:=ObjectText”).Exist
while ObjectText is used as a parameter which I have already defined. This should be very simple to do if only I knew how to… I prefer to reference the cell text than to use an index because the text can be anywhere in the table.

Thanks a lot, Stefan

Reply

25 Stefan November 30, 2009 at 5:54 am

Sorry, in the example Is used I mean innertext of course, not innerhtml. In my case, innerhtml and innertext are the same anyway. This is meant as a very general question, the same problem could be a reference to a website by parameter or something else.

Reply

26 Stefan November 30, 2009 at 7:02 am

OK, found out about it…
[...] .WebElement(”innertext:=” & ObjectText).Exist
Not very difficult I must admit, but I first experienced that it didn’t work this way for some reason.

Reply

27 Anshoo Arora November 30, 2009 at 1:18 pm

Hi Stefan,

I’m glad you figured it out. Whenever a value comes from a variable in a description, you will have to use the “ampersand &” character.

:)

Reply

28 Stefan December 2, 2009 at 4:35 am

Hi Anshoo,

again I’m having a question. I want to set global variables I’m using for several QTP-actions, such as
Set Google = Browser(“name:=Google”).Window(“text:=Google”)
Now I can only use this within the same action. How can I do this, will I need to define a public class I’m calling in each action?

Thanks, Stefan

Reply

29 Anshoo Arora December 2, 2009 at 11:28 am

Hi Stefan,

You can use a function library and declare the variable ‘Google’ as public within the library:

'In the associated function library:
Public Google

This will enable all actions to have complete access to your variable/reference.

Reply

30 Naresh December 3, 2009 at 2:46 pm

Hello All,

I am having issue with QTP

I have a Web table which has webelements in few cells, My application has Few cells which are Webelements and when double clicked will be Web Edits,

When i Spy the Object on each cell is shown as WebElement. however when I try to get the count the value is 0. I was wondring if we can work with Webelements in descriptive programming

ObjectCount2 = Browser(“Browser1″).Page(“Page1:”).Frame(“main_iframe”).WebTable(“name:=CCV-100″).ChildItemCount(3,iColIndex, “WebElement”)
Print ObjectCount2

Please help me

Reply

31 Anshoo Arora December 3, 2009 at 3:51 pm

Hi Naresh,

Is the cell itself a WebElement, which is to be clicked? Or, does the cell contain an element that you click?

If the cell itself is an element that you need to click, then you can use DOM methods instead:

Browser("Browser1").Page("Page1:").Frame("main_iframe").WebTable("name:=CCV-100")_
    .Object.Rows(2).Cells(iColIndex-1).Click

Reply

32 Naresh December 3, 2009 at 4:33 pm

Hello Ashoo,

Thnaks for the Quick Response, This has resolved my 30% of the issue,

The Issue is Few Cells in Table are Webelements, When Double clicked, will become WebEdits, where I set the values or Edit the Values depending on test requirements. now th issue is when i use the Above DOM Concept will resolve the problem of clicking the Row and column in table, however this Dom doesnot support the Set or Type the values to those cells.

I am New to the DOM concepts, if you can guide me to study material, i would really Appreciate the time and Effort.

Thanks a lot
Regards
Naresh

Reply

33 Anshoo Arora December 3, 2009 at 4:36 pm

After you click the cell, the exposed WebEdit should technically support the .Set statement. If that does not work for any reason, you can try this as well:

Browser("").Page("").WebEdit("").Object.Value = "Test"

Also, you can check W3Schools for a HTML DOM tutorial: http://w3schools.com/htmldom/default.asp

Reply

34 Debajit Hazarika December 14, 2009 at 8:59 am

First of all, I would like to thank and appreciate for coming up with such a nice Knowledge Resource on QTP. Great piece of work, indeed…!! I consider myself as a beginner in QTP and I am trying to learn the concept of Descriptive Programing. I found your website, read the articles and could not stop writing to you.
The way you present things and describe them is really very neat and clear, and impressive too. I found your site very different from others as I went through many QTP sites and blogs and know what they have. Sometimes, your comments and replies are much valuable than your articles….. :) That’s really nice. Now, I know I am in right place. So, I will start firing questions to you. I am sure you would address them with the same spirit, enthusiasm and patience.
Last but not the least, thanks for guiding beginner like me. All the best…….!!

Regards
Debajit

Reply

35 Anshoo Arora December 14, 2009 at 2:50 pm

Thank you Debajit. Thank you for your kind words. I’m deeply honored. :)

Please feel free to use the comments section of the relevant posts for your queries. I will try to answer them as quickly as possible.

Regards,

Anshoo

Reply

36 Renu February 17, 2010 at 2:02 pm

Hi Anshoo,

I ve small query. ” I ve generated one test script and when i copy the intire folder of this QTP script( must be along with repositories) for same test in different machine.it is throwing error.what can be the reason? pls specify

Thanks
Renu

Reply

37 Anshoo Arora February 19, 2010 at 2:01 am

Hi Renu,

What is the error message? Have you copied the contents to the same location in Machine2 from Machine1?

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: