What is Descriptive Programming?
Descriptive programming is used to execute operations on an Object in the AUT whose definition is not stored in the Object Repository. Using this mechanism, you can bypass identification from the Object Repository and supply the Object Description in the statement itself.
An object name is simply used to map an object in script with its description in an object repository. Meaning if you change the object name in your script and object repository, the script should run. Watch the following video on this concept
- Delete the Object Description of Agent Name Win Edit Box from the Object Repository. If you run the test again it will fail since it can not recognize the object. Let's examine the reason why the script is failing
- During Run Time, Micro Focus UFT identifies the operation that is performed on WinEdit box and the Object Description in Object Repository is stored as Agent Name. It uses this name to track the object in an object repository. For a parent, you cannot have two child objects with the same name. Hence, QTP uniquely maps the object in the repository. It then uses the stored description in the Object Repository and replaces the name with the description. It then uses this statement to identify the object in the application under test/li>
- Since in our case we had deleted this object description altogether the script fails/li>
- But what if instead of QTP replacing the object description, you as a tester directly specify the object descriptions in your script. This is nothing but "Descriptive Programming"
Types of Descriptive Programming
You can use Descriptive programming in two ways
Static Descriptive Programming
In Static Method, for object identification, you specify an object's property in the following format
This format is called property value pair and is enclosed in inverted commas>
If your object uses multiple descriptions for identification, you can specify those using commas>
So in our case, the description for Agent Name becomes
"nativeclass:=Edit", "attached text:=Agent Name:"
Dynamic Descriptive Programming
The second method of doing the same action is using Dynamic Descriptive programming
In case your script uses the descriptive programming object candidate multiple times, it will be very tiresome to specify all the property value pairs for each statement
In such cases, you can make use of Description Class provided by QTP
The syntax for creating a description object is
Set MyDescription = Description.Create(); MyDescription("property").Value = "property-value";
This is the Dynamic Method
Why Use Descriptive Programming?
- The million dollar question is why to use DP when the Object Identification process is handled by QTP
- Suppose you are assigned to test a job portal. You enter a search query into the portal and
- your test expects you to select all available jobs .and click the apply job
- But the no of jobs reflected will depend on the search query and jobs available at the time of script execution but there is no way to predict in advance the no of jobs that would be reflected
- In such cases, you can use descriptive programming. Even though you do not know the number and names of the checkboxes you do know the class for the objects as "WebCheckBox"
- You can use the ChildObject method to return objects belonging to a particular parent
- A line of code like -
Set allObjects = Browser("Jobs").Page("QTP").ChildObjects()
- Will return all child objects for this page.
- But we want only WebCheckBox objects. To do so we can create a filter creation object and set its property as web check box and pass this filter as an argument for the ChildObjects method
- In this case, only the checkboxes are returned.
- Next, you can write a code like this which access the entire collection of checkboxes starting from zero and sets all checkboxes ON.
- Next, you can click the apply button to complete the test
- You can also use Descriptive Programming to run objects which are difficult to record like Auto-Hide Panels, Objects with changing hierarchies, Nested Inner Objects, Sub-menus.
- You can also do advanced string manipulations using descriptive programming
- In conjunction with index property, descriptive programming could be very useful in identifying difficult objects.
- If you use programmatic description for an object in object hierarchy you will need to use description programming for succeeding child objects
- For example, for the page object, descriptive programming was used but for succeeding child object WinEdit Object Repository is used which is incorrect
- On the contrary here for both Page and WinEdit descriptive programming is used which is correct