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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
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?

# re: Latest Frustration with QTP

Left by Zakir Qureshi at 5/11/2010 1:52 AM
Gravatar
Hi,
There is a syntax error in Reporter.ReportEvent.
the comma is missing after micPass
it has to be like this "Reporter.ReportEvent micPass,"Link Found", "YES" "
please, correct me if i am wrong.

# re: Latest Frustration with QTP

Left by Zakir Qureshi at 5/11/2010 1:57 AM
Gravatar
Hi,
i found one more syntax error...
see .....Link("Link).Exist(0) Then
the ("Link) is not properly closed by inverted comma's it has to be ("Link").....
... also check the objects exists in the repository..with the same name...as used...means ....for Browser-"Browser" for Page-"Page" and for Link- "Link"....

# re: Latest Frustration with QTP

Left by Ravi at 7/26/2010 9:53 PM
Gravatar
Ankur (from relevant codes , I believe) , fantastic explanation , really wonderful.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910