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

Descriptive Programming in QTP – The Complete Guide : Part1

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

This article covers the basics of Descriptive Programming in QTP with the main aim to help you get familiarized with its basic syntax. The article uses an illustrative approach to help you understand the difference between Object Repository and Descriptive Programming code. And also to guide you through the process of creating descriptive programming code.


Descriptive Programming in QTP


Before you start looking into the details, the primary question that you have to answer is this – “What is Descriptive Programming in QTP?” In simple words, Descriptive Programming is the type of programming where you DON’T use Object Repository while writing your test scripts.


Simple enough? Well, after reading the above definition of descriptive programming, there might be many queries that may come to your mind –

>> Why do we eliminate object repository while scripting?

>> How to skip Object Repository and write scripts using Descriptive Programming?

>> What are the advantages/disadvantages of Descriptive Programming over Object Repository?

>> Are there any situations where using Descriptive Programming would be advantageous over Object Repository?


Before we begin answering the above queries, let us first see the structure of a line of code in QTP and understand how Object Repository fits in there. Once you are clear with this concept, understanding and using Descriptive Programming in your script becomes very very easy.

Structure of a QTP Statement and Object Repository

Let’s take an example to understand the below concept. Consider that you have to write the code which enters some text in Google Search. The code that you would write with the use of object repository would look something like this –

Browser("brGoogle").Page("pgGoogle").WebEdit("q").Set "google"


You can divide the above line of code into 2 parts –

a) The object hierarchy part (or simply the object part) denoted by Browser(“brGoogle”) .Page(“pgGoogle”) .WebEdit(“q”)

b) and the action part specified by Set “google”

So we can safely say that a QTP statement usually consists of 2 things – the object and the action.


Also, the object is something which is stored in the Object Repository. So when you run the above code, QTP will try to find out the object properties from Object Repository and then perform the action on that object.


So when you say that you want to write your script a such a manner that it doesn’t use object repository, it actually means that you have to write the object part of your statement in a different way such that it doesn’t go to Object Repository to find the object properties. Check the below diagram that illustrates the this concept.

Descriptive Programming in QTP



Now you know that in descriptive programming, you only need to modify the Object part of your code. But how do you do that? Well, the answer to this query also lies within the Object Repository.


Why does QTP refer to Object Repository while running a statement? QTP does it so that it can find the properties associated with the object from the Object Repository. So what if you directly provide the properties of the object in the code itself? If you do this, QTP finds the object properties in the code itself and therefore, there is no need for it to go and refer the Object Repository. And this is the way, you write your Descriptive Programming Code.. :–)

Writing Descriptive Programming Code

The below code snippet shows the syntax and example of Descriptive Programming approach.

'Descriptive Programming Syntax
Control("PropName1:=PropValue1","PropName2:=PropValue2", and so on..)

'Let's assume we have a Search button with properties as: name=Search & type=Submit.
'This can be written as follows using descriptive programming approach
WebButton("name:=Search","type:=Submit")


The below image depicts this concept more clearly.

Descriptive Programming in QTP



Using this concept, you can now re-write each of the objects as follows –

Browser(“brGoogle”) becomes Browser(“title:=Google”)

Page(“pgGoogle”) becomes Page(“title:=Google”)

WebEdit(“q”) becomes WebEdit(“name:=q”,”type:=text”)



Combining the above 3 objects, the complete statement can be written as –

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","type:=text").Set "google"



Descriptive Programming Example: As an example, let us see the descriptive programming code that searches for a string in google.com and then displays the total number of results found in a message box.

'Open Google.com
SystemUtil.Run "iexplore.exe", "http://www.google.com"

'Set value in Google Search Box
Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","type:=text").Set "automation repository"

'Click on Search button
Browser("title:=Google").Page("title:=Google").WebButton("name:=Google Search","type:=submit").Click

'Find out the number of search results displayed
sResults = Browser("title:=.*Google Search").Page("title:=.*Google Search").WebElement("html id:=resultStats").GetROProperty("innertext")

'Display the Result in a message box
Msgbox sResults


Over to you

This was all about the very basics of Descriptive Programming and its Syntax in QTP. In the next article, we will see some more important concepts that you can use with descriptive programming. Did you find this article useful? Let us know your thoughts about this using the comments section.

UPDATE: More on Descriptive Programming !!!  Read how to use regular expressions, description object, ordinal identifiers and more in the next article on DP – Descriptive Programming in QTP – Part 2

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

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
  • Pingback: Descriptive Programming in QTP – The Complete Guide : Part 2 - Automation Repository - Automation Repository()

  • Nice Work Pillai.. 🙂

  • Pingback: QTP Linear Framework – Complete Reference with Example - Automation Repository - Automation Repository()

  • Nithi

    Perfect Explanation….

    • Anish10110

      Thanks Nithi .. 🙂 Keep visiting…

  • Pingback: QTP Frameworks : Designing QTP Modular Framework from scratch - Automation Repository - Automation Repository()

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

  • Ravish

    Nice post.

    • Anish10110

      Thanks Ravish.. 🙂

  • pravs

    Hi ,
    Iam a beginner in QTP learning Process … its really nice info ..thanks
    Browser("title:="Google").Page("title:="Google").WebEdit("name:=q" , "type= text").Set "abc"
    The test run cannot continue due to a syntax error.

    Expected ')'

    Line (4): "Browser("title:="Google").Page("title:="Google").WebEdit("name:=q" , "type= text").Set "abc"".

    also under Testobjects Tree i dont see any icons as described in above figure :
    its empty ……..

    pls let me know how to correct these 2 ….

    • subhan

      ("name:=q" , "type= text")— here colon is missing after the property name 'type'

      • Anish10110

        This is in the comments, isn't it? Because I checked the code and couldn't find it there..

  • pravs

    Hi ,
    Thanks Anish
    iam really struggling to learn QTP then i see ur site thanks to you for uploading gr8 information which is really helpful
    just now i wrote this code Anish :
    'Open google browser
    Systemutil.run "iexplorer.exe", "http://www.google.com"
    'Set value in google search box
    Browser("title:="Google").Page("title:="Google").WebEdit("name:=q" ,"type= text").Set "abc"
    'Search with some Text in Search box
    Browser("title:="Google").Page("title:="Google").WebButton(name:="google Search",type=Submit").click()
    'find out no of search results
    rsresults=Browser("title:=".*Google Search").Page("title:=".*Google Search").webElement("html id ="resultStats").getROProperty("inner Text")
    'Display results
    msgbox (rsresults)

    iam getting the syntax error like ')' Expected at the end of the line …
    can u pls clarify if i did any mistake in my code and also my test object tree is empty ….
    do i need to do anything to see brgoogle and pgGoogle objects ….

    regarding the information thankyou can u also add more coding into it

    Looking forward to hear from you soon

    • Anish10110

      Hello Pravs…

      There are minor syntax errors in the code. You have written Browser("title:="Google"), but it should be written as Browser("title:=Google") i.e. before Google there should be no double quotes. This same error is repeated throughout your code, for other objects also.

      Also webElement("html id ="resultStats") should be webElement("html id:=resultStats") i.e := instead of simple =

      getROProperty("inner Text") should be getROProperty("innerText") i.e. no space between inner & Text.

      All these are very common minor mistakes which occur when you start with scripting.

      I didn't understand your 2nd query. "also my test object tree is empty …. ". Can you explain it in bit more detail?

      One more thing. If you are keeping a track of the comments, then its ok.. Otherwise you can provide your mail id while commenting so that I can reply you back to your e-mail id with the solution.

  • pravs

    Anish thank you so much for your clarification ….i thought i have provided email address
    thanks again

  • pravs

    Hi Anish , regarding the 2nd query its solved …..

    • Anish10110

      Cool.. 🙂 🙂 But what was the exact query?

  • Suraj

    Superb article well explained and excellent for beginners in QTP.

    • Anish10110

      Thank you Suraj.. I'm glad that you found the article useful.. 🙂

  • Anand

    Thanks 🙂

    • Anish10110

      Thank you Anand.. 🙂

  • Jayachandra

    HI Anish,

    First of all need to thank for the article it was exceptional but at line 11 i.e WebElement it is throwing error .
    Sresults=Browser("title:=.*Google Search").Page("title:=.*Google Search").WebElement("html id:= resultStats").GetROProperty("innertext")

    Can You correct me where am going wrong..

    • Anish10110

      Thank you Jayachandra.. 🙂 Glad that you liked the article.

      For the error, can you provide the exact error message that you got?

      • Jayachandra

        Cannot identify the object "[ WebElement ]" (of class WebElement). Verify that this object's properties match an object currently displayed in your application.

        Line (11): "Sresults=Browser("title:=.*Google Search").Page("title:=.*Google Search").WebElement("html id:= resultStats").GetROProperty("innertext")".

        Tip: If the objects in your application have changed, the Maintenance Run Mode can
        help you identify and update your steps and/or the objects in your repository.

        • Anish10110

          Hi Jayachandra,

          I ran the code in my system and it worked fine. Can you check the following thing.

          When QTP is showing this error, Google Search Page should be displayed with something like "About 8,620,000 results (0.18 seconds)" text below the search text box.

          If it still doesn't work, try the below code and see if it works. Let me know the result.

          'Open Google.com
          SystemUtil.Run "iexplore.exe", "http://www.google.com"

          'Set value in Google Search Box
          Browser("title:=Google.*").Page("title:=Google.*").WebEdit("name:=q","type:=text").Set "automation repository"

          'Click on Search button
          Browser("title:=Google.*").Page("title:=Google.*").WebButton("name:=Google Search","type:=submit").Click

          'Find out the number of search results displayed
          sResults = Browser("title:=.*Google Search.*").Page("title:=.*Google Search.*").WebElement("html id:=resultStats").GetROProperty("innertext")

          'Display the Result in a message box
          Msgbox sResults

          • raje

            Hi Anish …can u post script to click on a particular link if u know ..

          • Anish10110

            Hi,

            If you have the properties of the link, you can do it very easily. Example, Browser("B").Page("P").Link("text:=some text").Click

  • Jayachandra

    Hi Anish,

    I still recieve the similar error, and one more think i observed is when I tried to spy on Web Element for "html id" value is blank.
    Could you help me in working out.. on this..

    • Anish10110

      Hi Jayachandra,

      Can you email me the screenshot of the object spy and the screenshot of the web browser when the error occurs? We can then take it up from there. You an mail me at anish@automationrepository.com

  • Balamurugan

    Hi Pillai,

    It is really really very good article with pictorial representation which i never seen any other tutorial sites. It is seems like explaining to kid. Please don't stop your wonderful job at any cost.

    "GOD BLESS YOU".

    • Anish10110

      Hi Bala..

      Thank you for this wonderful feedback.. :):)

  • swathi

    Hi Anish,
    I'm getting an error in line
    Browser("title:=Google.*").Page("title:=Google.*").WebButton("name:=Google Search","type:=submit").Click
    The test run cannot continue due to asyntax error
    Expected ')'
    Canu pls help me out of this
    very useful information
    Thanks.

    • Anish10110

      Hi Swathi,

      This line seems fine. There might be a possibility that the issue might be there in some other line. Can you send me screenshot of the code when the error occurs. You can email me anish[at]automationrepository[dot]com.

  • Pingback: Basics of Keyword Driven Framework in QTP - Automation Repository()

  • Div

    Hi, There is a way to block other all sites other than our application, please let me know abt it

    • Anish10110

      Hi Div, In what sense do you want to block sites?

  • Pingback: Designing Keyword Driven Framework mapped at Operation Level – Part 1 - Automation Repository - Automation Repository()

  • Div

    Hi,

    Block in sense i should get winobject while spy those sites

    • Anish10110

      Div,

      I'm not sure if such a functionality exists. I have never used anything like this.

      But there is one feature wherein one can ignore the browsers. For example, suppose you open google first and the open facebook after that in another browser. Here, google will have CreationTime as 0 and Facebook will have CreationTime as 1.

      But lets say that you ignore the browser that has Google opened. That way even though you had opened Google first, Facebook will have CreationTime as 0, as QTP will ignore Google. But here when you spy the objects in Google page, it will be shown properly only. You will not get WinObject for the objects.

      This option can be accessed from —- Tools -> Options -> Web.

      Please let me know if this was helpful.

  • Pingback: Designing Keyword Driven Framework mapped at Operation Level – Part 2 - Automation Repository - Automation Repository()

  • uma

    Hi Anish,

    I am started learning QTP for me the site is excellent.

    I am getting ans unrecoverable error. when I commented 'Systemutil.run "iexplore.exe", "http:\google.com"
    and run the script

    Below is the error message displayed :
    Cannot find the "[ WebEdit ]" object's parent "[ Browser ]" [class Browser]. Verify that parent properties match an object currently displayed in your application.

    Line [1]: Systemutil.run "iexplore.exe", "http:\google.com".

    • ANSUDEEN IMRANKHAN

      Hi,

      check whether your script close after first time process.
      Then again you need to open if it is not open.

  • uma

    Hi Anish,

    I am new to QTP, it is really great that u r site is providing excellent information.

    Thanks,
    Uma

  • UMAQTP

    Hi Anish,

    Great site…………I am started learing QTP.

    • Anish10110

      Cool.. 🙂

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

  • Thangamani

    Hey Anish, this is Thangamani…

    You did a great job man..appreciated.

    • Anish10110

      Hey Mani… :):) How are you??? Long time….

  • Pingback: Desigining Keyword Driven Framework mapped at Functional Level – Part 2 - Automation Repository - Automation Repository()

  • Pingback: Designing Keyword Driven Framework mapped at Functional Level – Part 1 - Automation Repository - Automation Repository()

  • sneha

    Hi Anish,

    Your article is so helpful to learn QTP.

    Have you written any article on Advanced QTP features and QTP 11?

  • Sneha

    Thanks Anish

  • Miki

    Anish
    i just went through all comments and am wondering what i did wrong. I copied the code from the end of the first section and pasted to QTP.
    I am in QTP 11 and browser is IE8 (i'm including this because it seems relevant)

    i am getting error:
    Cannot find the "[ WebEdit ]" object's parent "[ Browser ]" (class Browser). Verify that parent properties match an object currently displayed in your application.

    Line (21): "Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","type:=text").Set "automation repository"".

    Tip: If the objects in your application have changed, the Maintenance Run Mode can
    help you identify and update your steps and/or the objects in your repository.

    -M-

    • Anish10110

      Sorry for the late response. But is it working now??

  • Pingback: Keyword Driven Framework | qtpscripts()

  • Pingback: QTP==>Key Word driven achitecture | dhirendrasoni()

  • Prashant

    Hi Anish,

    I am a newbie to QTP . I love the way you explain the topics.Its just awesome …….With the help of images, its very easy to understand…

    I am practicing QTP on Web app. But I stuck at one point…..

    The thing is…After creating a user it is shown as a link in user page..I wrote a function to check whether the link exist or not..but its not able to identify the link.
    Here is my function:===
    Function Link_Check(fLinkText)

    Dim MyObjct,MyPg

    Set MyPg=Browser("Title:=.*").Page("Title:=.*") 'Create a page object to point any open page in any open browser

    Set MyObjct = Description.Create()
    MyObjct("micclass").Value = "Link"
    MyObjct("html tag").value = "A"
    MyObjct("innertext").value = fLinkText

    If MyPg.Link(MyObjct).Exist(2) Then
    Link_Check = True
    Reporter.ReportEvent micPass,"Expected Link" , "Expected Link is present"
    Else
    Reporter.ReportEvent micFail,"Expected Link" , "Expected Link is Not present"
    Link_Check = False
    End If

    Set MyObjct = Nothing
    Set MyPg = Nothing
    End Function

    For calling this function I tried the below statement
    Link_Check"Stark, Tony (User1)"
    Link_Check (fLinkText) and providing the value in fLinkText variable
    Link_Check fLinkText and providing the value in fLinkText variable

    But nothing worked . I tried the below code also but gettin an error

    "Cannot identify the object "[ Link ]" (of class Link). Verify that this object's properties match an object currently displayed in your application."

    Browser("MyBrowser").Page("MyPage").Link("html tag:= A", "text:=Stark, Tony (User1)").Click

    These are the two properties QTP using to identify and click on it .I checked in OR ..and it worked in record and play back ..i disable the smart Identification as well

    Please help me out

  • Ram

    'Variable declaration

    Dim GoogleBrowser

    Dim GooglePage

    Set GoogleBrowser=Browser("name:=Google.*")

    Set GooglePage=GoogleBrowser.Page("title:=Google.*")

    'URL

    URL="http://www.google.com"

    SystemUtil.run "iexplore",URL

    'Write 'quicklearnqtp' in search box

    GooglePage.WebEdit("name:=q","type:=text","html tag:=INPUT").Set "quicklearnqtp"

    'Click on Google Search

    GooglePage.WebButton("name:=Google Search","index:=0","type:=submit","html tag:=INPUT").Click

    'Close browser

    GoogleBrowser.CloseAllTabs

  • Tapas

    very useful for beginners in descriptive programming . . . thnx

  • Sammy

    SUPER and very nice information

  • jayanthi

    Thankyou so much for your nice explanation,can you please explain loops and conditional statement.i understood the concept but i m able to able understand how to work in application.you are simply mismerise.

  • Manjunath

    Hi Anish,

    How do we come to know, what to use where like webbutton, webElement, set etc ?
    pls reply.

  • sushil

    Gr8 jobs ,,really helpful.

  • Pingback: Designing Hybrid Framework in QTP - Part 1 - Automation Repository - Automation Repository()

  • Siva

    simply super… the way of explanation is like giving fruit to the kid.

    Thank you sio much for you explanations with patience

    • Anish10110

      hehe.. nice one Siva.. 😀

  • Anu

    Hi Anish,

    I started learning QTP, when i tried parametrizing for the login screen of the flight app for the first row it is working fine but when it comes to the second row it is showing the error as below and i tried with Maintenance run mode as well..can u pls help with this

    Cannot find the "Agent Name:" object's parent "Login" (class Dialog). Verify that parent properties match an object currently displayed in your application.

    Line (5): "Dialog("Login").WinEdit("Agent Name:").Set DataTable("AgentName", dtGlobalSheet)".

    Tip: If the objects in your application have changed, the Maintenance Run Mode can
    help you identify and update your steps and/or the objects in your repository.

    • Ansudeen Imrankhan

      Hi,

      check whether your script close after first time process.
      Then again you need to open if it is not open

  • krishna

    nice explaination,, thank u 🙂

    • Anish10110

      Thank you Krishna.. 🙂

  • Ramakrishna

    Hi Anish,

    This is Ramakrishna working in MNC as a
    Manual Tester, i never shown interest studying about DP, But after
    reading above DP article, now i am showing interest for writing DP.

    The way you given logical example, simply Awesome .

    Keep it up

    Thanks,

    Ramakrishna

  • Kamal

    Neat explanation on the subject.Appreciate the effort involved.

  • Anusha

    Hi Anish,
    One of the QTP question asked in the interview is as below:
    How does QTP handle dynamic object incase none of the objects(say all are labels) on the application as no unique property.
    I answered as smart identification and ordinal identifies.
    Interviewer replied that smart identification is wrong. and all labels have same number ( so ordinal identifiers can not be used)
    Can you please tell me what is the correct answer?
    Thanks & regards,
    Anusha

    • vamshi

      may be
      repositoriescollection.add"file path"
      file path->object repositories saved location address

  • Pingback: QTP Tutorial 9 : Descriptive Programming in QTP – The Complete Guide : Part 2 | Tech Lessons()

  • Peter Son

    Your information about qtp is really interesting. Also I want to know the latest new techniques which are implemented in qtp. Can you update it in your website?

    <a href="http://www.fita.in/qtp-training-in-chennai/">Qtp training Chennai</a>

  • Naren

    HI Anu ,

    To answer ur question , u can use Visual relation identifier . By this method u can identify ur dynamic object with the nearby static object

  • Pingback: QTP Frameworks : Designing QTP Modular Framework from scratch | Tech Lessons()

  • Pingback: Designing Hybrid Framework in QTP – Part 1 | Tech Lessons()

  • Nidhish

    is there any difference in String based Description and Using Description Object? when should we use any of this approach??

  • Swarupananda Tantubay

    I am getting an error message like this while running the code for google search
    Cannot find the "[ WebEdit ]" object's parent "[ Browser ]" (class Browser).
    Verify that parent properties match an object currently displayed in your application.
    Line (38): "Browser("title:=Google").Page("title:=Google").WebEdit("name:=q","type:=text").Set "automation repository"".
    2. Also HP MyFlight Sample Application opens up every time i am trying to run this code which searches with a string in google. Why is this happening. I am working with QTP 12.52. Is the above error message coming because of this window
    3. Also how can i get the properties of objects i mean do we always use Object Spy for the same?

  • w_aslam

    Hello,

    I am trying to test a script using following syntax: Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("html id:=totalLoanAmountField","class:=TL_NPI_L1 spa-input-text","name:=add_amount").Set "30000"
    The test runs and passes but the value"30000"doesn't get entered. any suggestions??

  • WhatIsSEO

    Hello Sir,
    After the time process the script will automatically closes how?
    thanks for this post.
    <a href="http://whatisseo.in/digital-marketing.php"&gt; Digital Marketing Course </a>

  • This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me…

  • This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me…

  • what if you directly provide the properties of the object in the code itself?
    thanks for the post.

  • Nancy jeinth

    Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point. https://www.quora.com/Where-can-I-find-VLSI-jobs-in-Chennai/answer/Livewire-Velachery1#utm_source=google&utm_medium=blog%20comments&utm_campaign=Livewire%20Velachery

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