Geeks With Blogs
Maryanne's Blog Another Geek with A Blog
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 on Thursday, November 6, 2008 5:56 PM QuickTest Pro | Back to top


Comments on this post: Latest Frustration with QTP

# re: Latest Frustration with QTP
Requesting 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.
Left by Nicole on Nov 07, 2008 8:34 AM

# re: Latest Frustration with QTP
Requesting Gravatar...

Hi,

Even I found dat issue few days but couldnt figrued it out whats the exact reason. Your post certainly helped me.
Left by Yoginder on Dec 03, 2008 4:08 AM

# re: Latest Frustration with QTP
Requesting 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?
Left by Ankur Jain on Dec 26, 2008 11:36 AM

# re: Latest Frustration with QTP
Requesting 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.
Left by Zakir Qureshi on May 11, 2010 1:52 AM

# re: Latest Frustration with QTP
Requesting 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"....

Left by Zakir Qureshi on May 11, 2010 1:57 AM

# re: Latest Frustration with QTP
Requesting Gravatar...
Ankur (from relevant codes , I believe) , fantastic explanation , really wonderful.
Left by Ravi on Jul 26, 2010 9:53 PM

# re: Latest Frustration with QTP
Requesting Gravatar...
Ankur,
The way you put out here for boolean comparison was cool.
Browser("Browser").Page("Page").Link("Link").Exist(0) AND True
Left by Dipu Krishnan on Feb 21, 2012 10:57 AM

# re: Latest Frustration with QTP
Requesting Gravatar...
please solve this for me why the if statement is not true even if i put 1 ticket

systemutil.Run"C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("regexpwndtitle:=Login").Winedit("attached text:=Agent Name:").set "Manoj"
Dialog("regexpwndtitle:=Login").Winedit("attached text:=Password:").set "mercury"
Dialog("regexpwndtitle:=Login").winbutton("text:=OK").Click
Window("text:=Flight Reservation").AcxEdit("acx_name:=MaskEdBox").Set"121212"
Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").Select"Denver"
Window("text:=Flight Reservation").WinComboBox("attached text:=Fly To:").Select"Frankfurt"
Window("text:=Flight Reservation").WinButton("text:=FLIGHT").Click
Window("text:=Flight Reservation").Dialog("text:=Flights Table").WinList("window id:=2001").Click
Window("text:=Flight Reservation").Dialog("text:=Flights Table").WinList("window id:=2001").Select 5
wait(1)
Window("text:=Flight Reservation").Dialog("text:=Flights Table").WinButton("regexpwndtitle:=OK").Click
Window("text:=Flight Reservation").WinEdit("window id:=1014").Set"Manoj Kumar"

n= inputbox("Enter no. of tickets")
Window("text:=Flight Reservation").WinEdit("attached text:=Tickets:","window id:=1029").Set n
price = Window("text:=Flight Reservation").WinEdit("attached text:=Price:","window id:=1030").GetROProperty("text")
Tot = Window("text:=Flight Reservation").WinEdit("attached text:=Total:","window id:=1031").GetROProperty("text")

lenp =len(price)
lent =len(Tot)

price = right(price,lenp-1)
msgbox price

Tot = right(Tot,lent-1)
msgbox Tot

pntot =price * n
msgbox pntot

lenpn =len(pntot)
lent =len(Tot)
msgbox lent
msgbox lenpn


If Tot = pntot Then

Msgbox " The Total is equal to price X No." 'why is it not getting compared in if
else
Msgbox " The Total is NOT equal to price X No."

End If

window("text:=Flight Reservation").Close
Left by manoj on Sep 07, 2012 4:09 AM

Your comment:
 (will show your gravatar)


Copyright © Maryanne Sweat | Powered by: GeeksWithBlogs.net