What is Descriptive Programming in UFT?
Entering / Providing objects information directly into the test script is called Descriptive Programming.When QTP/UFT records any action on any object,it tries to identify the object with some of its properties. And stores them in object repository. Later point of time , during execution, it takes reference from it and tries to find out the object in the application and perform set of operations.
So, if an object is not present in the object repository, QTP/UFT can not identify the object and perform operation on it.
With the fast development of application and agile way of developing software advocates more about descriptive programming. Imagine we need to design our test script without the GUI. Yes!! it is possible. Descriptive programming provides information to QTP/UFT bypassing object repository. The same object information is passed to QTP/UFT so that it can identify the object.
Lets think about a person whom we don’t know. When we meet for the first time, we create an image of that person. Like name, tentative age,gender,height,if the person wear specs or not etc. For us to remember that persons these are enough. we will be able to identify the person in our next meet by using our stored properties of that person. These are mandatory properties. There are some other things we can notice. We may also notice the shirt color, trouser color, some more details. They are assistive properties. The help to identify the person uniquely. But they may change.
What is Descriptive Programming in UFT??
Likewise if we need to identify a textbox, the first thing we will be looking is the name or id. This will help me to identify the textbox.In this method of script creation, we no need to have Object Repositories.
But assume that we have a special application which is dynamic in nature. So with the stored object description QTP/UFT will not be able to identify the objects. Say after loggin we have a welcome message say Welcome <<UserName>>. Upon clicking on the username it will navigate to the actual page.
This will work fine if the same user logs in but fails when another user logs in as the stored object description does not match to the application object.So we need to find an another way of coding.
This is called Descriptive programming.
In real world if the person says I want to meet you and I will be seating some coffee hose, table number-2. I will be in red shirt. Then we will not try to find the person, directly go to that coffee house and go to table no-2. Now if I see a person with red shirt , we will get the person. Is not it??
So , in this method we provide information about the object to QTP and request it to perform search operation and carry out tasks.
In real project if the GUI is not available or the project size is getting bigger(OR will also bigger), we use descriptive programming.
a) Descriptive Programming based Test scripts are faster in execution than Repository based Test scripts.
b) Scripts are portable (we can run these scripts from any machine easily)
c) Maintenance is easy (less amount of resources)
d) We can start Test Execution process even though Application is not ready.
Descriptive programming is basically 2 types.
1. Static Programming
2. Dynamic Programming
In this style of script generation, we provide objects information directly into the script.
Invokeapplication "C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe" dialog("text:=Login").Activate dialog("text:=Login").Winedit("attached text:=Agent Name:").Set "asdf" dialog("text:=Login").Winedit("attached text:=Password:").Set "mercury" dialog("text:=Login").Winbutton("text:=OK","width:=60").Click
1. Dialog, WinEdit and WinButton – Test Objects
2. text, attached text – Property names
3. Login, Agent Name:, Password:, OK – Property values or Logical Names of the Object
4. Activate, Set, Setsecure, Click – Methods
If we feel one property information is not sufficient for recognizing the object uniquely, then we can provide more properties information by separating with commas.
If we want to get objects information (Test objects, properties and values), we can use object spy feature. This feature is available in Tools Menu, in local repository and in repository manager.
If we want maintain ‘Objects information’ in centralized location then we can use Constants.
Const Login=”text:=Login”, Agent=”attached text:=Agent Name:”
Const Pwd =”attached text:=Password:”, Ok=”text:=OK”
Note: we can declare no of Constants in a line by separating with Camas (,), if we take other line then we have to use Const Statement again.
Creating a Library file
Place Constants in Notepad and save as .vbs file
Associate the Library file to QTP (File->Settings->Resources-> Click add (+) icon-> Browse path of the Library file->Click Apply and click Ok buttons
Otherwise, we can load the library file during run-time
ExecuteFile “Path of the Library file(.vbs)”
After that create the Test Script using Constants
Creating the Test Script using Constants:
Invokeapplication "C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe" Dialog(Login).Activate Dialog(Login).Winedit(Agent).Set "asdf" Dialog(Login).Winedit(Pwd").Set "mercury" Dialog(Login).Winbutton(Ok).Click
If we maintain Object Information in the centralized location, then we can handle modifications easily.
In this style of script generation, first we create description objects, provide properties information and use description objects in the test script.
Creating Properties Collection Objects
//Entering Properties Information into Objects
oAgent(“attached text”).value=”Agent Name:”
//Generating Tests using Properties collection Objects
Invokeapplication “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Note1: Create Description objects and put into one library file, by associating that library file, we can generate tests.
Note2: Dynamic programming is some difficult in preparation than static programming but maintenance is very easy.
In this style of script creation also, we can maintain Objects information in the Centralized location by putting collection objects in a Library file.
Well,Here is the technique to write descriptive progranning…the main boost of my secrets…
Please follow the threads..
Descriptive Programming is an advanced concept of QTP coding. Testers can handle the application without using the OR by implementing the Descriptive programming.
- They are reusable
- Modification of the script becomes easy in compare to QTP Code
- This is very useful when applications are not available
- It is flexible for high performance of the application .
- This is very speedy technique for execution
- It can efectivey handle the object implementation problem of an application.
If the property values changes,it is necessary to upgrade the description.So maintenance is an issue for descriptive programming.
Few Common Example of Descriptive Programming:
How To Count The Numbers of Links On A Page and click on a link in QTP/UFT?
SystemUtil.Run http://www.yahoo.com/ Set aa=description.Create aa("htmltag").value="A" // This type of coding is called descriptive programming. set bb=Browser("name:=Fun.*").Page("title:=Fun.*").childobjects(aa) cc=bb.count msgbox cc
There is another way to find out the count of link
Set oDesc = Description.Create() oDesc("micclass").Value = "Link" //here we are filtering the object oDesc by its default class micclass. micclass of a link is "Link" Set Links = Browser("Browser").Page("Google").ChildObjects(oDesc) NumberOfLinks = Links.Count() Msgbox NumberOfLinks
even, if, you need to click on a specific link you can modify the script little bit..say i have a link called yahoo.com and I need to click on the mail link.
Logic is again same …find out all the links
Now the extra is that we need to check if the link name is “Mail” . If so generate an click event.
SystemUtil.Run http://www.yahoo.com/ Set aa=description.Create aa("htmltag").value="A" 'either specifying here -------------------------------- aa("name").value="Mail" ------------------------------- set bb=Browser("name:=Fun.*").Page("title:=Fun.*").childobjects(aa) cc=bb.count for i=0 to cc-1 if bb(i).getROProperty("name")="Mail" then//link name bb(i).click exit for end if next
How to check all checkboxes in a webpage/window in UFT or QTP?
Set a=Description.Create a("html tag").value="input" a("type").value="checkbox" Set b=Browser("name:=").Page("title:=").childobjects(a) c=b.count msgbox c For i=0 to c-1 b(i).set "on" Next
How to Close All Browser from QTP/UFT Code?
Sub CloseAllBrowsers() Systemutil.CloseProcessByName("IEXPLORE.exe") wait(5) End Sub
Now you can do further enhancement on this.
Say I have opened a meeting window and want to show my running window to our client or my seniors or there might be cases when I might open a test management tool like QC which runs on IE and want to run the test. So every time I will not be interested to open QC page.
This is a small modification on the code which will be helpful for such scenarios.
On Error Resume Next Dim intWndCnt Dim oDesc, oWnd 'Create Object description Set oDesc = Description.Create ' Set oWnd = Desktop.ChildObjects(oDesc) intWndCnt = oWnd.Count For i = 0 to intWndCnt - 1 Set TmpObj = oWnd.item(i) strTmpTitle = oWnd.item(i).GetROProperty("Text") If instr(1,strTmpTitle, "Microsoft Internet Explorer",1) > 0 Then If instr(1,strTmpTitle, "Mercury Quality Center",1) > 0 Then 'msgbox "Title :" & oWnd.item(i).GetROProperty("Text") Else 'msgbox "Close : & oWnd.item(i).GetROProperty("Text") oWnd.item(i).close End if End If Next 'Clean up Set oDesc = nothing Set oWnd = nothing
How to Calculate Number of Opened Browsers in QTP/UFT?
Function Browser_Count() Set objBrowser =description.create() objBrowser("micclass").value="Browser" Set sBrowsers=desktop.childobjects(objBrowser) ibCount=sBrowsers.count If ibCount<>0 Then Browser_Count=ibCount Else Browser_Count=1 End if Set objBrowser=Nothing Set sBrowsers=Nothing End Function
How to Close Oracle Form in QTP/UFT??
This is one more situation which arises very common to an ERP test engineers. Most of the time we rely on QTP’s record feature. But this is scenario which occurs all most in every window of Oracle ERP Testing.
So instead of doing record playback in every time I tried to use some descriptive approach to make it a general case. So this can be treated as common function across the scenario.This is a code rather sub/procedure where we need to pass the form name as a parameter and this will close the form.
Sub ERP_CloseForm(sFrmName) If OracleFormWindow("short title:="& sFrmName).Exist Then OracleFormWindow("short title:="& sFrmName).CloseForm End If End Sub
How to Get Browser Title in QTP or UFT?
‘ we are creating a blank object named as sbrowser.
‘ we are assigning the sbrowser object as “Browser
How to Count Number of open Browsers in Desktop Using QTP/UFT?
For this the concepts we will be using are:
2. Descriptive programming