Sunteți pe pagina 1din 4

1/28/12

DP Part 4

Common mistakes | KnowledgeInbox

KnowledgeInbox
Automation Solution & Services DP Part 4 Common mistakes

March 22, 2008 3:27 PM

This article would go over some common mistakes people make while using Descriptive Programming (DP) in QTP. Using strings with Pattern Let s assume we want to click a link Logout (Tarun) on my web page. Two possible methods that can be used are Method 1
Bosr"icls:Bosr)Pg(mcls:Pg".ik"et=oot(au))Cik r e(mccas=r e".ae"icas=ae)Ln(t :Lgu Trn".lc

Method 2
Stoec=DsrpinCet e Ds ecito.rae oec"et)Vle="oot(au) Ds(t ".au Lgu Trn" Bosr"icls:Bosr)Pg(mcls:Pg".ikoec.lc r e(mccas=r e".ae"icas=ae)Ln(Ds)Cik

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 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 1
Bosr"icls:Bosr)Pg(mcls:Pg".ik"et=oot\Trn))Cik r e(mccas=r e".ae"icas=ae)Ln(t :Lgu (au\".lc

knowledgeinbox.com/articles/qtp//dp-part-4-common-mistakes/

1/4

1/28/12

DP Part 4

Common mistakes | KnowledgeInbox

Method 2
S oec=D ci inCe e e D e p o. a oec"e ".a e="oo \T n) D ( )Vl Lg (a \" Bo e(mcca :Bo e".ae"ica :Pg".ikoec.lc "icl = )Pg(mcl =ae)Ln(D )Cik

Method 3
S oec=D ci inCe e e D e p o. a oec"e ".a e="oo (a n" D ( )Vl Lg T ) 'on D o e a h a ea e l epe in e l g a o. oec"e ".e l Epe in=Fle D ( )Rg a o a

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

S oec=D ci inCe e e D e p o. a oec" m a".a e="AL" D (h l g)Vl TBE oec"ica ".a e="eTbe D (mcl )Vl Wbal" oec"ne e ".a e="bd" D (in )Vl ace oec" e e ".a e="bd" D (o )Vl ace oec"nehm".a e="l;bd& ;l; & ;l;dg;bd& ; dg;l; & ;l; bd& ; D (in l)Vl & o g & g & & acel / & & / g & / o g " oec" ehm".a e="l;al& ;l;bd& ;l; & ;l;dg;bd& ; dg;l; & ;l; bd& ; D (o l)Vl & beg & o g & g & & acel / & & / g & / o g & oec"o ".a e=1 D ( )Vl oec"o ".a e=1 D (cl )Vl

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
S oec=D ci inCe e e D e p o. a oec" e e ".a e="bd" D (o )Vl ace

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 sensitive Using Class Name instead of micclass Don t know why by Mercury/HP preferred to show micclass as Class Name in the object spy. This misleads many DP user to
knowledgeinbox.com/articles/qtp//dp-part-4-common-mistakes/ 2/4

1/28/12

DP Part 4

Common mistakes | KnowledgeInbox

c ea e a de c ip ion i h non-e i en p ope

cla

name

Cla

Name ho n in objec

'eo i tewogw Blw s h rn a Bosr"ls Nm:Bosr) rwe(Cas ae=rwe" 'eo i tergtw Blw s h ih a Bosr"icas=rwe" rwe(mcls:Bosr) 'eo i tewogw Blw s h rn a Stoec=DsrpinCet e Ds ecito.rae oec"ls Nm".au ="rwe" Ds(Cas ae)Vle Bosr oec"il".au =" tte Ds(tte)Vle M il" 'eo i tergtw Blw s h ih a Stoec=DsrpinCet e Ds ecito.rae oec"icas)Vle="rwe" Ds(mcls".au Bosr oec"il".au =" tte Ds(tte)Vle M il"

P in i h P in F iendl Add o Reddi Po o Delicio 1 pe Li e Po on +1'd mbleUpon oS hi Add o LinkedIn Po o T i e Have questions related to this article? Want to request a new article? Use our forums to post our questions Po on Google B Po o Facebook Send ia Gmail
knowledgeinbox.com/articles/qtp//dp-part-4-common-mistakes/ 3/4

1/28/12

DP Part 4

Common mistakes | KnowledgeInbox

Tags sed - cannot, Class, Class Name, Common, Descriptive, Descriptive Programming, identify, micclass, Object

Copyright

2012 KnowledgeInbox | | | | |

knowledgeinbox.com/articles/qtp//dp-part-4-common-mistakes/

4/4

S-ar putea să vă placă și