Micro Focus QTP (UFT) Forums
To calculate the page load time using a user defined function - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: To calculate the page load time using a user defined function (/Thread-To-calculate-the-page-load-time-using-a-user-defined-function)



To calculate the page load time using a user defined function - Renu0113 - 09-29-2009

I have written the following function to calculate the load time for a page.
Objective: Google home page opens
Click on Google Maps link
Get StartTime
Once Google Maps page arrives, get StopTime
Difference between StopTime and StartTime is the time the page takes to load.

Problem:
Even after the last step, the arrow is again at Step 3
(Browser("Bro_Google").Page("Pag_Google").Link("name:="&LnkName).Click)
It doesnt stop at the last line,i.e at msgbox and doesnt provide me the result.
Also, the result for msgbox StartTime is empty, no value
and for StopTime its 0..

Code/Function is:

Code:
Public Function CheckLoadTime(ByVal LnkName,ByVal BroName,ByVal PagTitle)
Browser("Bro_Google").Page("Pag_Google").Sync
Browser("Bro_Google").Page("Pag_Google").Link("name:="&LnkName).Click
StartTime=MercuryTimers.Timer("Timer1").Start
msgbox StartTime
Browser("name:=" & BroName).Page("title:=" & PagTitle).Sync
StopTime=MercuryTimers.Timer("Timer2").Stop
msgbox StopTime
CheckLoadTime=StopTime-StartTime
End Function
Call CheckLoadTime("Maps","Google Maps","Google Maps")
msgbox CheckLoadTime(LnkName,BroName,PagTitle)

Saket,I am Sorry, I meant to post another issue I am facing in the same context, but I posted the old query.Sorry.


Please help.


-Joshi


RE: To calculate the page load time using a user defined function - Saket - 09-29-2009

Hi Joshi,
It is causing because you have sarted a timer('Timer1' ) and stopping another timer ('Timer2').
if you have started timer1 then you should stop the same timer only.

you can use ElapsedTime method to get the time required to do the mentioned action by QTP.

the aother issue has been discussed in another thread by you - solution is use only a single statement to call you function.
if you will call it twice then obviously it will stuck at the position you mentioned

try the code below

Code:
Public Function CheckLoadTime(ByVal LnkName,ByVal BroName,ByVal PagTitle)
Browser("Google").Page("Google").Sync
Browser("Google").Page("Google").Link("name:="&LnkName).Click
wait(2)
StartTime=MercuryTimers.Timer("Timer1").Start
Browser("name:=" & BroName).Page("title:=" & PagTitle).Sync
StopTime=MercuryTimers.Timer("Timer1").Stop
CheckLoadTime=MercuryTimers("Timer1").ElapsedTime
End Function

msgbox CheckLoadTime("Maps","Google Maps","Google Maps")



RE: To calculate the page load time using a user defined function - Renu0113 - 09-30-2009

Thanks everyone!
I get it now.
Smile
I have a question. I want to see the load time,no. of links etc using the checkpoint now, for Google homepage.
I inserted the standard checkpoint(while recording), I have load time=2, no. of images=3, no. of links=30.
Now, when I run the recorded script(checkpoint) on Google homepage, it fails.
According to the results,it failed for "install Google chrome" link and "make Google my homepage" link.
Why does this happen?
Thanks,
Joshi


RE: To calculate the page load time using a user defined function - Saket - 09-30-2009

Hi Joshi,

Please open a new thread for your new question.
always put one query per thread.

!!Thread is closed now!!