使用对象库(OR)还是描述性编程(DP)

    技术2022-05-20  45

    Descriptive Programming (DP) vs Object Repository (OR)

    by Anshoo Arora on August 10, 2009

     photo credit: dkalo

    DP vs OR: Which is better?

    This has been a never ending debate and if you follow QTP forums, you will see a thread pop-up every few days. Most commonly, the OP is trying to inquire which one would be better (vague?), which one would require less maintenance time, which one is more user-friendly, which has the performance upside, which one will my boss admire more etc.

    The answer isn’t simple.

    That’s why this has been a never ending debate :)

    I do not guarantee that after reading this post, you will have an answer, but I am sure with some planning, you will be able to make up your mind as to which one would be the better alternative in the long run.

    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 WebEdit Window("nativeclass:=Test").WinEdit( "name:=editNewName" ).Set "DP"   'Incorrect description for WebEdit Window("nativeclass:=Test").WinEdit( "name:=editnewname" ).Set "DP"   'Incorrect description for WebEdit 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.

    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.

    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:

    Object Repository Front End GUI

    WhiteBox style DP

    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 [Credits: Yogindernath.

    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 [Credits: Marc Miedemo].

    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 :)

    References1. Connected Testing

    If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.


    最新回复(0)