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 an 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 a set of operations.
So, if an object is not present in the object repository, QTP/UFT can not identify the object and operate 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.
Let us think about a person whom we don’t know. When we meet for the first time, we create an image of that person. Like the name, tentative age, gender, height, if the person wears 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. 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 at 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 that is dynamic. So with the stored object description QTP/UFT will not be able to identify the objects. Say after logging we have a welcome message says 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 another way of coding.
This is called Descriptive Programming.
In the 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 a redshirt. 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 a 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 operations and carry out tasks.
In a real project, if the GUI is not available or the project size is getting bigger(OR will also bigger), we use descriptive programming.
When to use descriptive programming?
Apart from the above reason, there are few other situations when we need to opt for descriptive programming. They are as follows:
- Our object repository gets huge due to a large project. And larger the OR in size, it will impact the execution performance. Now to reduce dependency on OR, we can go for descriptive programming.
- The objects in the application are dynamic and need special handling to identify the object. The best example would be of clicking a link which changes according to the user of the application, Ex. ” Logout < < UserName > > “.
- When you don ‘ t want to use object repository at all. Modification to a test case is needed but the Object repository for the same is Read-only or in shared mode i. e. changes may affect other scripts as well.
- When a webpage or an application is still not developed, that time, it is not possible to add the object directly from the application or UAT. In that case, we can still descriptive programming to generate our code by seeing the technical specification document.
- Say we need to verify a table data. There are n numbers of data to verify. These n data are divided into say 20 pages. Each page contains the Next, the Previous button. So for 20 pages, there will be 20*2=40 button objects created. To avoid such huge object creation, we can use descriptive programming.
- If there are n numbers of textboxes present inside a UAT. in that case only value changing is the index of the textboxes. Say for first text box the name is text_1 and for second textbox the name of the textbox is text_2 and so on. In such a condition, adding them to an object repository is not a feasible option. Descriptive programming can be really helpful.
- If the same page of UAT is getting changed due to customer specification and being an automation engineer we can insert all possible variations into different object repositories. Now by coding, we can load and unload the shared object repository based on the customer scenario. But this changing may impact long execution. To minimize this risk, we can go for descriptive programming.
Advantages of Descriptive programming:
- Descriptive Programming based Test scripts are faster in execution than Repository based Test scripts.
- Scripts are portable (we can run these scripts from any machine easily).
- Maintenance is easy (less amount of resources).
- We can start the Test Execution process even though the Application is not ready.
Descriptive programming is 2 types.
1. Static Programming-By describing the form of the string arguments.
2. Dynamic Programming-By creating properties collection object for the description.
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, Set secureSetsecure, 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 features. This feature is available in Tools Menu, in the local repository, and repository manager.
If we want to maintain ‘Objects information’ in a 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 another 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
execute file “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
we can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object’s name. The general syntax is:
TestObject("PropertyName1:=PropertyValue1", "... ", " PropertyNameX:=PropertyValueX")
- TestObject – the test object class could be WebEdit, WebRadioGroup, etc..
- PropertyName:=PropertyValue- the test object property and its value.
Each property:=value pair should be separated by commas and quotation marks. Note that we can enter a variable name as the property value if we want to find an object based on property values we retrieve during a run session.