Download presentation
Presentation is loading. Please wait.
1
DESCRIPTIVE PROGRAMMING IN QTP (UFT)
2
Introduction Also known as Programming Descriptions
Provides a way to perform operations on objects (mostly dynamic) that are not present in OR
3
When and where to use DP? Handling dynamic object property
Using external functional library When OR is high When Application is not ready yet Suppose we have a web application that has not been developed yet. In that case OR wont work. But if we know the descriptions of objects that will be created, we can start off the scripts. when several identical objects need same operations On same Page Suppose we have 15 text boxes on a webpage and there names are in the form txt_1, txt_2 … and so on. Now adding all these 15 objects in OR would not be a good approach. We can simply go for descriptive programming On Different Page Suppose we have 3 navigation buttons on a webpage . For 10 pages flow, it would mean adding 30 objects in OR . which is not a good approach.. We can simply go for descriptive programming.
4
How to write DP? DP is not limited to a particular technology. It can be used across technologies and add-inns in QTP. 2 ways 1. By giving description in the form of string arguments (Inline DP or Static DP) 2. By creating properties collection object for the description (Dynamic Descriptive Programming)
5
Inline DP Syntax: Test Object( “PropertyName1:=PropertyValue1”, “PropertyName2:=PropertyValue2”………… “PropertyNameN:=PropertyValueN” Where, Test Object is the test object class. This could be Browser, Web Edit, WebRadioGroup etc. PropertyName:=PropertyValue is the test object property-value pair. Note: “propertyName1:=PropertyValue1” is correct. “PropertyName1 :=PropertyValue2” is incorrect. space
7
DP statements for demo flight reservation application
QTP doesn’t record any property for a browser. Browser shown above can be written as Browser(“micclass:=Browser”) QTP doesn’t record any property for a Page. Page shown above can be written as Page(“micclass:=Page”)
8
When you object spy username textbox you get, Web Edit object shown above can be written as WebEdit(“type:=text”,”name:=us erName”, “html tag:=INPUT”)
9
Combining all these statements together, DP statement Equivalent to Normal Recorded Statement is
Browser(“micclass:=Browser”).Page(“Micclass:=Page”).WebEdit(“typ e:=text”,”name:=userName”,”html tag:=INPUT”).Set “Mercury”
10
Dynamic Descriptive Programming
By creating properties collection object for the description. Example: Dim oDesc ‘Declare an object variable Set Odesc=Description.Create ‘Create Empty Description oDesc(“type”).Value=“text” oDesc(“name”).Value=“userName” oDesc(“html tag”).Value=“INPUT” So previous INLINE DP statements would look like, Browser(“micclass:=Browser”).Page(“Micclass:=Page”).WebEdit(oDesc).Set “Mercury”
11
regular expression in dp
Regular expression is used in a checkpoint. It enables to quick test to identify the objects and text strings. We can use regular expression for 1. Defining property values of an object in dialog boxes or programmatic description 2. parameterizing step 3. creating check points with varying values Characters and sequence that can be used in QTP : (click) Some Symbols: *------> to complete text and characters \d----> for a digit \s----> for a space \S----> for a string > for 1 char [ ]-----> Range Operator
12
examples of regular expression
1. first number/digit should come as 5,6,7 and 2nd digit as 2,3,4 Regular Expression:[5-7][2-4] 2. To validate a number of length 10 digits provided that digits should be between 2-9 Regular Expression:[2-9]{10} 3. Any number of length 5 Regular Expression:\d{5} 4. for number of digits of any length Regular Expression: d+ $223.20==> \$\d+\.\d{2} (d+ for number of digits of any length) $223.20===>\$[1-9][1-9][1-9]\.\d{2}
13
title=" Google ajkdahalhduiakah”
Regular expression: Google.* time=12:53 PM Regular expression : \d{2}\:\d{2}[ PM or AM]{2} Or \d{2}\:\d{2}[ P or A]M{2}
14
using regular expression in dp
Dim oDesc ‘Declare an object variable Set Odesc=Description.Create ‘Create Empty Description oDesc(“type”).Value=“text” oDesc(“name”).Value=“userName\d\d\d” ‘(instead of writing userName123) oDesc(“html tag”).Value=“INPUT Note: If you wish to turn off regular expression, then oDesc(“name”).RegularExpression=False
15
using ordinal identifier in dp
There are 3 ordinal identifiers in QTP Index Location Creation Time why ordinal identifiers? For example, when multiple browsers are opened, we can identify which browser is opened first, with the help of creation time or setting index. Browser(“micclass:=Browser”).Page(“Micclass:=Page”).WebEdit(“type:=text”, “name:=userName”,”html tag:=INPUT”, “index:=0”).Set “Mercury” Browser(“micclass:=Browser”).Page(“Micclass:=Page”).WebEdit(“type:=text”, “name:=userName”,”html tag:=INPUT”, “index:=1”).Set “Mercury”
16
difference between class vs classname vs micclass
When we object spy some class(say button),it shows two different properties Classname and Class. Class Name is the basic essence of that object. If Class Name gets changed the object itself would get changed. Hence, an object of type button will always be shown as WebButton under Class Name, a hyperlink would always be shown as Link, a browser object would always be shown as Browser and so on. A point to note here is that, while object spy shows the property as Class Name, the same property should be written as micclass while using Descriptive Programming. For ex: Browser(“micclass:=Browser”).Page(“micclass: =Page”).WebButton(“micclass:=WebButton”,”P ropertyName:=PropertyValue”).Click Note: micclass Mercury Interactive Class Content
17
what is: gettoproperty
Returns the value of the specified identification property from the test object description. Example :1 (when object is in Object Repository) SystemUtil.Run "iexplore.exe" Browser("Google").Navigate abc = Browser("Google").Page("Yahoo! Mail: The best").WebEdit("login").GetTOProperties ("name") msgbox abc Example 2: (with descriptive programming) Set obj = Browser("name:=Sign in to Yahoo!").Page("title:=Sign in to Yahoo!").WebEdit("html id:=username") msgbox obj.GetTOProperty("html id")
18
what is: getroproperty
Returns the current value of the specified identification property from the object in the application. Example –'The following example uses the GetROProperty method to retrieve ‘the Y coordinate of the AcxCheckBox object relative to the top left 'corner of the screen. Sub GetROProperty_Example() Set Value= Browser("Flight").Page("Flight").AcxCheckBox("LogicalName").GetROProperty("abs_y") End Sub
19
what is: settoproperty
The SetTOProperty changes the value of a test object property. Changing the property doesn't affect the OR or Active Screen, but just the way QTP identifies the object during runtime. Actually, this changes the properties of the temporary copy of the object stored in RAM by QTP. Any changes you make using the SetTOProperty method apply only during the course of the run session, and do not affect the values stored in the test object repository. Example: Set obj = Browser("name:=Sign in to Yahoo!").Page("title:=Sign in to Yahoo!").WebEdit("html id:=username") msgbox obj.GetTOProperty("html id") 'Would retrieve the object html id from the test object description, whether it's in the OR or DP defined 'Now we set the name property obj.SetTOProperty "name", "loginzzzzz"'And retrieve it msgbox obj.GetTOProperty("name")
20
Thank you…!!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.