Pages

Monday, September 13, 2010

Descriptive Programming vs Object Repository : Which is better?

 

The answer isn’t simple.

1. In Expert View, DP and OR statements are written in the following manner:

'OR

Browser( "Google" ).Page( "Google" ).WebEdit( "q" ).Set "Google Search"

'DP

Browser( "title:=Google" ).Page( "title:=Google" ).WebEdit( "name:=q" ).Set "Google Search"

With DP, the properties are written with their corresponding values. OR, on the other hand, shows only a logical description of the object.

2. A DP parent will only recognize a child that has DP style layout. In other words, you CANNOT add a child to a DP parent that has its properties stored in the OR. Example:

'Will not work: Browser is DP whereas Page and WebEdit are OR

Browser( "title:=Google" ).Page( "Google" ).WebEdit( "q" ).Set "Google Search"

'Will not work: Browser and Page are DP whereas WebEdit is OR

Browser( "title:=Google" ).Page( "title:=Google" ).WebEdit( "q" ).Set "Google Search"

However, an OR parent will recognize both OR and DP style children:

'Will work: Browser is OR whereas Page and WebEdit are DP

Browser( "Google" ).Page( "title:=Google" ).WebEdit( "name:=q" ).Set "Google Search"

'Will work: Browser and Page are OR whereas WebEdit is DP

Browser( "Google" ).Page( "Google" ).WebEdit( "name:=q" ).Set "Google Search"

3. Writing good DP for Objects takes experience and skill. Even though DP has become extremely popular, improperly written DP can lead to performance issues, maintenance headaches etc. Its quite a different story with OR where you record the objects and QTP creates the hierarchy.

4. The user must be careful when using DP: it is case sensitive (except in the case of Web Applications). Do not confuse this with how VBScript works. If the value of a property ‘html id’ is ‘txtZip’ then it must be coded as ‘txtZip’, not ‘txtzip’ or ‘TXTZIP’. QTP will only find the object if the value is written exactly as in the Object Spy. Example (WebEdit’s name property is retrieved as ‘editNewName’):

'Correct description for WinEdit

Window("nativeclass:=Test").WinEdit( "name:=editNewName" ).Set "DP"

'Incorrect description for WinEdit

Window("nativeclass:=Test").WinEdit( "name:=editnewname" ).Set "DP"

'Incorrect description for WinEdit

Window("nativeclass:=Test").WinEdit( "name:=EDITNEWNAME").Set "DP"

5.Unlike OR, DP does not have auto-complete. All object descriptions must be coded out manually. This can be quite time consuming, and even frustrating for people who’re used to working with OR.

clip_image001[4]

Object Repository Auto Complete Feature

6.Unlike OR’s ‘Highlight in Application’ feature, when searching for an object hierarchy written in DP, you must execute the line of code to locate the object in the application. Another way would be to keep a record of all objects, which can be quite tedious.

clip_image002[4]

Object Repository Highlight in Application Feature

7. DP supports ChildObjects (to create the description object, you MUST use DP). Description object example:

Dim oDesc

Set oDesc = Description.Create

'Add a name property to the description

oDesc( "name" ).Value = "q"

'Add a html tag property to the description

oDesc( "html tag" ).Value = "INPUT"

8. On average, DP is slower than OR (note: on average!). With DP, QTP creates the an object from the provided hierarchy of DP and locates the object in the application before performing an event. Demo:

'OR: 9.74 seconds

For i = 0 to 99

Browser("Google").Page("Google").WebEdit("q").Set "QTP"

Next

'DP: 14.64 seconds

For i = 0 to 99

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"

Next

9. OR has a GUI which makes is easy to understand object hierarchies and maintain objects. DP hierarchies are code statements. Example:

clip_image003[4]

for DP

Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(Desc)

10. .Object is available to both DP and OR:

'OR

Browser("Google").Page("Google").WebEdit("q").Object.Value = "QTP"

'DP

Browser("title:=Google").Page("title:=Google").WebEdit("name:=q").Object.Value = "QTP"

11. Objects have logical names in OR which makes it easy to identify them. Sadly, DP doesn’t, since its based on principles of a white-box.

12. This is strictly for OR, but at times you will notice that when working with applications, objects are added as: WebEdit_1, WebEdit_2, WebEdit_3 … WebEdit_n and so on. This can be extremely cumbersome to deal with, and it takes quite long to rename all the objects in OR to give them meaningful names.

13. Code written with DP can be easily copied/pasted onto other scripts or functions. With OR based scripts, a simple copy/paste will not result in a working script. All the repositories (local/shared) would have to be associated with the test to make it executable. Therefore, when creating test with many reusable components, its generally easier to work with DP in comparison to OR unless there is a comprehensive use of Shared Object Repositories 

14. Object Repositories have capabilities to perform single-point maintenance, whereas with DP, during changes, all objects undergo manual updates. In situations where there are several changes in the AUT, OR can prove to be a better performer

If you feel I have missed something and must be added or corrected, please post a comment and I will update this post, giving full credit to you. Thanks :)

No comments:

Post a Comment