Descriptive Programming in QTP – The Complete Guide : Part1
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.
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.
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.
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.
Pingback: Descriptive Programming in QTP – The Complete Guide : Part 2 - Automation Repository - Automation Repository()
Pingback: QTP Linear Framework – Complete Reference with Example - Automation Repository - Automation Repository()
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()
Pingback: Basics of Keyword Driven Framework in QTP - Automation Repository()
Pingback: Designing Keyword Driven Framework mapped at Operation Level – Part 1 - Automation Repository - Automation Repository()
Pingback: Designing Keyword Driven Framework mapped at Operation Level – Part 2 - Automation Repository - Automation Repository()
Pingback: Descriptive Programming in QTP | Learn QuickTest Pro (QTP)()
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()
Pingback: Keyword Driven Framework | qtpscripts()
Pingback: QTP==>Key Word driven achitecture | dhirendrasoni()
Pingback: Designing Hybrid Framework in QTP - Part 1 - Automation Repository - Automation Repository()
Pingback: QTP Tutorial 9 : Descriptive Programming in QTP – The Complete Guide : Part 2 | Tech Lessons()
Pingback: QTP Frameworks : Designing QTP Modular Framework from scratch | Tech Lessons()
Pingback: Designing Hybrid Framework in QTP – Part 1 | Tech Lessons()