What is Descriptive Programming?
To understand the concept of descriptive programming lets understand the significance of an objects name in QTP. An object name is simply used to map an object in script with its description in 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. Lets examine the reason why the script is failing
- During Run Time, QTP 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 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 all together 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 ProgrammingYou can use Descriptive programming in two ways
In Static Method , for object identification you specify an objects 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:"
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 Syntax for creating an 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 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 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 WebcheckBox 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 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 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