site
stats
By Anish Pillai Anish Pillai Posted under QTP Concepts | QTP Tutorials for Beginners

Descriptive Programming in QTP – The Complete Guide : Part 2

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

In the previous article, we saw the basics of Descriptive Programming in QTP. In this article, we will discuss few more important concepts that will help you use descriptive programming more effectively. Let’s see each of these concepts one by one.


Using Regular Expressions in Descriptive Programming

Consider the following scenario – You have to write a script where you have to click on the inbox link in GMail. But you would have noticed that the number of unread emails is also displayed together with the Inbox link in GMail. Also, the number of unread emails changes very frequently.

GMail Inbox Link

So how do you handle such scenarios when you use Object Repository? Yes, you use Regular Expression when specifying the object property in OR. Well, you can use the same regular expressions concept with Descriptive Programming also. Let’s see how this is done.

Now when you don’t have any unread mails in GMail, the inbox link will be displayed as ‘Inbox’ but in case there are any unread mails, it is appended with the Inbox text as Inbox(2), Inbox(14) etc. Here you will notice that the common text in both the cases is ‘Inbox’. The most basic regular expression that we can use here is Inbox.* . And for the link, the regular expression would look like Link(“innertext:=Inbox.*”). The complete code is shown below –

Browser("title:=Gmail.*").Page("title:=Gmail.*").Link("innertext:=Inbox.*").Click

In the above code, we have used regular expression for Browser and Page title also. This is done because when you open any mail in Gmail, some text gets appended after Gmail in the title. So this code will work from Inbox as well as from some other page in Gmail.


Using Description Object in Descriptive Programming

In the first part of Descriptive Programming in QTP series, we covered the most basic method of using Descriptive Programming where you specify the object property and value directly with the statement. This approach is shown below.

Browser("title:=Google").Page("title:=Google").WebEdit.....
Browser("title:=Google").Page("title:=Google")......
Browser("title:=Google").Page("title:=Google")......

Here you can notice that the object property for browser and page objects are specified multiple times. Now suppose that the this property gets changed at some point in the future. In such a scenario, you would have to do a lot of rework to update the scripts. To avoid this, you can use an alternative method where you can specify the object properties and methods in Description Object and then use this object in your statement. Below code highlights this approach.

Set oBrowser = Description.Create
oBrowser("title").Value = "Google"

Set oPage = Description.Create
oPage("title").Value = "Google"

Browser(oBrowser).Page(oPage).....
Browser(oBrowser).Page(oPage).....
Browser(oBrowser).Page(oPage).....


Alternatively you can use one more method to shorten your code –

Set oGoogle = Browser("title:=Google").Page("title:=Google")

oGoogle.WebEdit("name:=q","type:=text").Set "automation repository"
oGoogle.WebButton("name:=Google Search","type:=submit").Click
.....
.....

In both the above cases, the object property and value is written at only a single place. So if there is any change in the object property, it needs to be done at few places and thus the amount of rework is significantly reduced.


Combining both Object Repository and Descriptive Programming

You can combine both Object Repository and Descriptive Programming approaches in your scripts. While doing so you have to take care of one thing. In the same statement, you can start with OR and then use DP, but you cant do it the reverse way. That is, you can’t first use DP and then move over to OR. The below code illustrates this concept.

'Correct Way - OR can be used before DP
Browser("Google").Page("title:=Google")....

'Wrong Way - OR can't be used after DP
Browser("title:=Google").Page("Google")....


Using Ordinal Identifiers in Descriptive Programming

Many a times when you write scripts, you might need to include ordinal identifiers (index, creation time, location) in the object repository. You can use ordinal identifiers in Descriptive Programming also. Let’s see an example for the same.

Example: Ordinal Identifiers in Descriptive Programming. In this example,the code will open 2 internet explorer browsers and open different URLs in both the browsers.

SystemUtil.Run "iexplore.exe"  'Browser with CreationTime 0
SystemUtil.Run "iexplore.exe"  'Browser with CreationTime 1

Browser("CreationTime:=0").Navigate "http://www.google.com"
Browser("CreationTime:=1").Navigate "http://www.yahoo.com"

Based on the Creation Time ordinal identifier, the above code opens google.com in the first browser and yahoo.com in the second browser.

In the next article in this series, we will see some examples of Descriptive Programming. Meanwhile, if you have any inputs, feedback, queries regarding this article or this topic, you can let us know about it using the comments section.

If you enjoyed this article, you can join our blog to get new articles delivered directly in your inbox.

To check out more tutorials, visit our QTP Tutorials page. You can also check the Archives page to view the list of all our articles.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
  • Geeta

    This website has been by far the BEST way of understanding the functionality of different features in QTP. I am a beginner to QTP and have been struggling to understand QTP for sometime now . Needless to say, this is a really great way of explaining things from the perspective of a new comer who wants to know using the feature – when, where , why and how , and not going through the simple QTP help that only explains 'How' and not When/where/why !
    Kudos to you for coming up with such a great website.

    • Anish10110

      Thank you Geeta for the feedback.. 🙂 🙂

  • Pingback: Data Driven Framework in QTP : The Complete Guide – Part 1 - Automation Repository - Automation Repository()

  • pavan

    very good… 🙂

    • Anish10110

      Thank you Pavan.. 🙂

  • Abhijeet

    Hi Anish,

    The QTP framework related stuff was excellent. I really learnt a lot. But i am struggling with the coding part in VB. The VB stuff that you have uploaded is good but it's not much helpful with respect to QTP. Can you please share some more VB related topics which can directly be used for implementation in QTP.

    Anyways great resource for learning QTP.

    • Anish10110

      Thank you Abhijeet for your feedback.. 🙂

      Regarding VBScript concepts, what sort of additional information are you looking out for?

  • Pingback: Descriptive Programming in QTP - The Complete Guide: Part 1 - Automation Repository()

  • hari

    good job anish , really a very good site for learning qtp concepts

    • Anish10110

      Thank you Hari.. 🙂 Keep visiting.. 🙂

  • rama

    hi Anish
    im new to QTP,shld v write every each n step code for application.

    for ex; lets consider login page
    Dialog("Login").WinEdit("Agent Name:").Type "xyz"
    Dialog("Login").WinEdit("Password:").SetSecure "4ab7a2d45ab7f90a0279430e6836a126be044819"
    Dialog("Login").WinButton("OK").Click
    Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click

  • UMAQTP

    Hi Anish,

    Can you give me an real time example where we use both DP and OR please?

    • Anish10110

      I cant think of any generic realtime example of this. This mostly depends upon the application that you work on. There was one application that I worked on where for an end to end order, there were 100's of status. And each status was displayed on the webpage in a rectangular box. And as soon as the status of the order changed, the properties of the rectangle changed. For this scenario we had used both DP and OR approach.

  • Pingback: Descriptive Programming in QTP | Learn QuickTest Pro (QTP)()

  • Pingback: complete real time scripts of qtp « TESTING HUB()

  • tejas

    Hi Anish, This is Tejas

    You did a great Great Job. I know how much we struggle to learn QTP. You presented things in easy & conceptual manner which makes user to understand faster.

    I want to share my video presentation with you. Please have a look. I tried my level best as a beginner to present high level picture of automating my manual project using QTP hybrid framework.

    As a beginner i automated using OR. My next assignment is to automate using descriptive programming. please guide me for the same.

    Here is my presentation link – <a href="http://www.youtube.com/watch?v=EPPU17Ofez4&quot; target="_blank">http://www.youtube.com/watch?v=EPPU17Ofez4</a&gt;

    Please visit once.

  • tejas

    Hi Anish, This is Tejas

    You did a great Great Job. I know how much we struggle to learn QTP. You presented things in easy & conceptual manner which makes user to understand faster.

    I want to share my video presentation with you. Please have a look. I tried my level best as a beginner to present high level picture of automating my manual project using QTP hybrid framework.

    As a beginner i automated using OR. My next assignment is to automate using descriptive programming. please guide me for the same.

    Here is my presentation link – <a href="http://www.youtube.com/watch?v=EPPU17Ofez4&quot; target="_blank">http://www.youtube.com/watch?v=EPPU17Ofez4</a&gt;

    Please visit once.

  • Prashanth L

    Amazing.:) Website..Can you share Some more examples of Descriptive programming..??

    Regards
    Prashanth L

  • Manjunath

    Hi Anish,

    Thanks a lot, very very valuable info for beginners.
    Is qtp supports only IE browser ? or will it support other too.?

  • vinay

    A big thanks for you. Easily understable

    • vinay

      Can you help me with more VBscripting skills required for QTP. Thanks

  • vv

    Nice artical easy to digest. Thansk Anish.

  • Nada

    Hi, how to get a datacell in QTP dataDable?

  • siva

    If i am opening more browsers (say 10 or more than that ) can we using a write single line of code to open more browsers or tab.

    • siva

      If i am opening more browsers (say 10 or more than that ) can we write single line of code to open more browsers or tab.

  • zuber

    About the combining of OR and DP…why we cant write the statement as
    starting DP then OR(wrong way)..is there any specific reason?

  • Arshdeep Kaur Sethi

    Thanks Anish It's really a gr8 site:)

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×