We can use
Descriptive programming in two ways
- Static Method
- Dynamic Method
Static Method:
In Static Method , for object
identification we specify an objects property in the following format “property:=values”,
This format is called property value
pair and is enclosed in inverted commas “”. If our object uses multiple descriptions for identification, we
can specify those objects using commas. So if we take an example of
login page of Flight reservation application then in that case, the description
for Agent Name will be in this way
"nativeclass:=Edit",
"attached text:=Agent Name:"
Dynamic Method:
The second method of doing the same
action is using Dynamic Descriptive programming. In case if our script
uses the descriptive programming object candidate multiple times, it will be
very difficult to specify all the property value pairs for each statement. In
such cases we can make use of Description Class provided by
QTP Syntax for creating an description object. Set is used to create
object and define them.
Syntax:
Set MyDescription =
Description.Create();
MyDescription("property").Value
= "property-value";
This is
the Dynamic Method
For example if we take a web application and we want to write a
descriptive programming code for that in QTP
Browser(“brGoogle”).Page(“pgGoogle”).WebEdit(“q”).Set “google”
We have to consider the Object hierarchy while we are writing Descriptive programming and also first when we write a descriptive programming and try to Execute it the QTP will first go through the Object repository and find out whether that object is present in that OR or not
So when we say that we want to write our script in a such a manner that it doesn’t use object repository, it actually means that we have to write the object part of our statement in a different way such that it doesn’t go to Object Repository to find the object properties.
Now we understand that in descriptive programming, we only need to modify the Object part of our code. In order to do that we take the help of Object repository only. Why does QTP refer to Object Repository while running a statement because QTP can find the properties associated with the object using this Object Repository only. So if we directly provide the properties of the object in the code itself QTP finds the object properties in the code itself and therefore, there is no need for it to go and refer the Object Repository. And this is the way, we write our Descriptive Programming Code.
Why Use Descriptive Programming?
- The million dollar question is why we use DP when the Object Identification process is handled by QTP
- Suppose if we are assigned to test a job portal. We enter a search query into the portal and
- The test expects we to select all available jobs .and click the apply job
- But the number of jobs reflected will depend upon 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, we can use descriptive programming. Even though we do not know the number and names of the checkboxes we do know the class for the objects as "WebCheckBox"
- We 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 we can write a code like this which access the entire collection of checkboxes starting from zero and sets all checkboxes ON.
- Next we can click apply button to complete the test
- We 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.
- We 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 we use programmatic description for an object in object hierarchy we 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
No comments:
Post a Comment