dppart4-generalissues-tarunlalwani

Upload: je-de

Post on 14-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 DPPart4-GeneralIssues-TarunLalwani

    1/5

    DP Part 4 Common Mistakes

    Author(s): (1)tarun_lalwani

    Written On:

    Keywords:

    QTP, Quick Test,

    This article would go over some common mistakes people make while using

    Descriptive Programming (DP) in QTP.

    Using strings with Pattern

    Lets assume we want to click a link Logout (Tarun) on my web page. Two

    possible methods that can be used are

    Method 1Browser("miccclass:=Browser").Page("micclass:=Page").Link("text:=Logout

    (Tarun)").Click

    Method 2Set oDesc = Description.Create

    oDesc("text").Value = "Logout (Tarun)"

    Browser("miccclass:=Browser").Page("micclass:=Page").Link(oDesc).Click

    Now both the above methods will fail giving below mentioned error

    Cannot identify the object [ Link ] (of class Link). Verify that this objects

    properties match an object currently displayed in your application.

    Cannot identify the link object

    Looking through the naked eyes on the web page the link does exist indeed

    mailto:[email protected]:[email protected]:[email protected]://knowledgeinbox.com/wp-content/uploads/cannot-identify-object.jpegmailto:[email protected]
  • 7/30/2019 DPPart4-GeneralIssues-TarunLalwani

    2/5

    So what went wrong? The problem was with the characters ( and ) present in

    the text of the link we used. By default QTP treats all DP properties as regular

    expression (r.e.) patterns and (xxx) is considered as a group of patter xxx. The

    text Logout (Tarun) when treated as a r.e. gets a literal meaning of Logout

    Tarun, and since there is no such link on the web page QTP throws an error. To

    avoid such situations we need to escape the regular expression characters using

    the escape character \. Now we have three different solutions to correct the

    problem

    Method 1Browser("miccclass:=Browser").Page("micclass:=Page").Link("text:=Logout

    \(Tarun\)").Click

    Method 2Set oDesc = Description.Create

    oDesc("text").Value = "Logout \(Tarun\)"

    Browser("miccclass:=Browser").Page("micclass:=Page").Link(oDesc).Click

    Method 3Set oDesc = Description.Create

    oDesc("text").Value = "Logout (Tarun)"

    'Do not treat the value as regular expression.

    oDesc("text").RegularExpression = False

    Browser(miccclass:=Browser).Page(micclass:=Page).Link(oDesc).Click

    IMO Method 3 should be preferred for a neater coding as we are using the actual

    text of the link.

    Overpopulated description while identifying objects

    An overpopulated description does not help in recognizing the object. We should

    use minimum no. of properties which are stable enough to recognize the object

    on every single run. Consider the below overpopulated description

    Set oDesc = Description.Create

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

    oDesc("micclass").Value = "WebTable"

    oDesc("innertext").Value = "abcde"

    oDesc("outertext").Value = "abcde"

    oDesc("innerhtml").Value = "abcde"

    oDesc("outerhtml").Value =

    "abcde"

    oDesc("rows").Value = 1

    oDesc("cols").Value = 1

  • 7/30/2019 DPPart4-GeneralIssues-TarunLalwani

    3/5

    Consider the following advices while create such a description

    rows and cols are dynamic properties which might change if the table

    gets updated. These properties should be avoided

    Only one of the properties from innertext, outertext, outerhtml and

    innerhtml should be used

    outerhtml and innerhtml properties should be avoided as they

    contains various tags and difficult to express

    When using Browser().Page().WebTable(oDesc) we can skip

    specifying the micclass and html tag properties also because as soon as

    we enclose oDesc with the WebTable() test object these two properties

    are mostly implied.

    Considering the above points we can reduce our description to just

    Set oDesc = Description.Create

    oDesc("outertext").Value = "abcde"

    Underpopulated description while using ChildObjects

    Though we reduced the no. of properties in the description object when identified

    a table in the last section but while using ChildObjects method we should make

    sure the following

    Maximum description properties should be used to reduce the final

    result set. Though we should still follow the advices specified in earlier

    section of overpopulated descriptions except the last one (Where we

    ignore micclass and HTML tag).

    When using ChildObjects to find WebElements, html tag should

    always be provided to avoid errors.

    Property names used in description should be as the same case

    provided in the QTP help file. IMO changing the case sometimes causes

    general run error during script run. Though there is no documentation

    proving that description names are case sensitiveUsing Class Name instead of micclass

    Dont know why by Mercury/HP preferred to show micclass as Class Name in

    the object spy. This misleads many DP user to create a description with non-

    existent property class name

  • 7/30/2019 DPPart4-GeneralIssues-TarunLalwani

    4/5

  • 7/30/2019 DPPart4-GeneralIssues-TarunLalwani

    5/5

    oDesc("title").Value = "My title"