Latest Frustration with QTP

Because of QTP, I now know that its possible to stare a hole in your monitor trying to puzzle out why a section of code isn't working like you'd expect it to.  And here's what I mean:


If Browser("Browser").Page("Page").Link("Link).Exist(0) = True then
Reporter.ReportEvent micPass "Link Found", "YES"
End If

Now I stared a hole in my monitor this afternoon trying to figure out why if the *.Exists(0) in debug mode equals True, then why on earth is this line of code not reporting a true condition for the If Then.

Why ....  Why  ... 

I added debug login, I added msgbox reports I added all sorts of debug logic to try to figure out why this wasn't working.

Finally...I started looking at txt files that represent other scripts and code I've written in the past...when suddenly I note that these other scripts if they are evaluating an Exists(0) function they just say


If Browser("Browser").Page("Page").Link("Link).Exist(0) Then
Reporter.ReportEvent micPass "Link Found", "YES"
End If


WITH NO = TRUE!!!

And so I removed the = TRUE from my code and PRESTO everything started working...everything was right with the world again.


DUH.....Talk about making you feel stupid....

Oh well..at least I found the bug...

posted @ Thursday, November 06, 2008 5:56 PM

Print

Comments on this entry:

# re: Latest Frustration with QTP

Left by Nicole at 11/7/2008 8:34 AM
Gravatar
I've run into that countless times with HTML. I've sat staring at the code for a web page for a day more more, unable to fathom why there's a one-inch vertical line at the bottom of a page.

This is why I did not become a programmer ;p It's too much like math for Nicole's brain.

# re: Latest Frustration with QTP

Left by Yoginder at 12/3/2008 4:08 AM
Gravatar

Hi,

Even I found dat issue few days but couldnt figrued it out whats the exact reason. Your post certainly helped me.

# re: Latest Frustration with QTP

Left by Ankur Jain at 12/26/2008 11:36 AM
Gravatar
Equals to operator (=) compares string or numeric expressions. What is returned by Browser("Browser").Page("Page").Link("Link).Exist(0) is boolean as can be checked from msgbox Typename(Browser("Browser").Page("Page").Link("Link).Exist(0))

When a boolean expression (on the LHS) see an equal to operator, it must be implicitly getting changed into string or numeric expression depending on whether string or numeral is present on the other side(RHS).

So in your case both of these should work...

String comparison (String - "True" - is present. Note the quotes):
If Browser("Browser").Page("Page").Link("Link).Exist(0) = "True" then
Reporter.ReportEvent micPass "Link Found", "YES"
End If

Numeric Comparison: (Numeral -1- is present)
If Browser("Browser").Page("Page").Link("Link).Exist(0) = 1 then
Reporter.ReportEvent micPass "Link Found", "YES"
End If

If you want to compare Boolean expressions on both sides use AND

If Browser("Browser").Page("Page").Link("Link).Exist(0) AND True then
Reporter.ReportEvent micPass "Link Found", "YES"
End If

Trust, that makes sense?

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345