RSS Feed

QTP(1) ——- Descriptive programming in QTP

Posted on

Introduction:

This document demonstrates the usage of Descriptive programming in QTP 8.20. Italso discusses situations where Descriptive programming can be used. UsingDescriptive Programming automation scripts can be created even if the applicationhas not been developed.
Descriptive Programming:
Whenever QTP records any action on any object of an application, it adds somedescription on how to recognize that object to a repository of objects called objectrepository. QTP cannot take action on an object until unless its object description isin the Object Repository. But descriptive programming provides a way to performaction on objects which are not in Object repository.
Object Identification:
To identify an object during the play back of the scripts QTP stores some propertieswhich helps QTP to uniquely identify the object on a page. Below screen shots showsan example Object repository
2-3c436ffaf8
Now to recognize a radio button on a page QTP had added 2 properties the name of the radio button and the html tag for it. The name the left tree view is the logicalname given by QTP for the object. This can be changed as per the convenience of the person writing the test case. QTP only allows UNIQUE logical name under samelevel of hierarchy. As we see in the snapshot the two objects in Browser->Page nodeare “WebTable” and “testPath”, they cannot have the same logical name. But anobject under some other node can have the same name. Now with the currentrepository that we have, we can only write operation on objects which are in therepository. Some of the example operations are given below
Browser(“Browser”).Page(“Page”).WebRadioGroup (“testPath”).Select “2”
cellData = Browser(“Browser”).Page(“Page”).WebTable(“WebTable”).GetCellData (1,1)
Browser(“Example2”).Page(“Page”).WebEdit(“testPath”).Set “Test text”
When and Why to use Descriptive programming?
1. Below are some of the situations when Descriptive Programming can be considereduseful:1.The objects in the application are dynamic in nature and need specialhandling to identify the object. The best example would be of clicking a link
which changes according to the user of the application, Ex. “Logout<>”.
2. When object repository is getting huge due to the no. of objects being added.If the size of Object repository increases too much then it decreases theperformance of QTP while recognizing a object.
3.When you don’t want to use object repository at all. Well the first questionwould be why not Object repository? Consider the following scenario whichwould help understand why not Object repository
Scenario 1: Suppose we have a web application that has not been developedyet. Now QTP for recording the script and adding the objects to repositoryneeds the application to be up, that would mean waiting for the applicationto be deployed before we can start of with making QTP scripts. But if weknow the descriptions of the objects that will be created then we can stillstart off with the script writing for testing.
Scenario 2: Suppose an application has 3 navigation buttons on each andevery page. Let the buttons be “Cancel”, “Back” and “Next”. Now recordingaction on these buttons would add 3 objects per page in the repository. For a10 page flow this would mean 30 objects which could have been represented just by using 3 objects. So instead of adding these 30 objects to the repositorywe can just write 3 descriptions for the object and use it on any page.
4.Modification to a test case is needed but the Object repository for the same isRead only or in shared mode i.e. changes may affect other scripts as well.
5.When you want to take action on similar type of object i.e. suppose we have20 textboxes on the page and there names are in the form txt_1, txt_2, txt_3and so on. Now adding all 20 the Object repository would not be a goodprogramming approach.
How to use Descriptive programming?
There are two ways in which descriptive programming can be used1.By creating properties collection object for the description.2.By giving the description in form of the string arguments.
1.By creating properties collection object for the description.
To use this method you need first to create an empty description Dim obj_Desc‘Not necessary to declare Set obj_Desc = Description.Create Now we have a blank description in “obj_Desc”. Each description has 3properties “Name”, “Value” and “Regular Expression”.obj_Desc(“html tag”).value= “INPUT”
When you use a property name for the first time the property is added to the collection and when you use it again the property is modified. By default each property that is defined is a regular expression. Suppose if we have the following description
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt.*”
This would mean an object with html tag as INPUT and name starting with txt.Now actually that “.*” was considered as regular expression. So, if you want theproperty “name” not to be recognized as a regular expression then you need toset the “regularexpression” property as FALSE
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt.*”
obj_Desc(“name”).regularexpression= “txt.*”
This is how of we create a description. Now below is the way we can use it
Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test”
When we say .WebEdit(obj_Desc) we define one more property for ourdescription that was not earlier defined that is it’s a text box (because QTPsWebEdit boxes map to text boxes in a web page).
If we know that we have more than 1 element with same description on the page then we must define “index” property for the that description
Consider HTML Given Below
<INPUT type=”textbox” name=”txt_Name”>
<INPUT type=”textbox” name=”txt_Name”>
Now the html code has two objects with same description. So distinguishbetween these 2 objects we will use the “index” property. Here is the description for both the object 
For 1st textbox:
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “0”
For 2nd textbox:
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “1”
Consider the HTML Code given below:
<INPUT type=”textbox” name=”txt_Name”>
<INPUT type=”radio” name=”txt_Name”>
We can use the same description for both the objects and still distinguishbetween both of them 
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
When I want to refer to the textbox then I will use the inside a WebEdit objectand to refer to the radio button I will use the description object with thWebRadioGroup object. 
Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set Test” ‘Refers to the text box
Browser(“Browser”).Page(“Page”).WebRadioGroup(obj_Desc).set “Test” ‘Refers to the radio button
But if we use WebElement object for the description then we must define the“index” property because for a webelement the current description would return two objects.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: