Page 1 of 1

Measure the response time of a Web page Part II

PostPosted: Fri Dec 04, 2009 4:07 pm
by Mike
Error management is done in this example using the OnAction Error structure (not available in WinTask Lite).

Code: Select all
Sub process_error()
'When an execution error occurs, this Sub is called
'Any code can be inserted in this Sub - just a warning: if an error
'occurs within this proc, that will create an infinite loop.
'If many lines are executed in this proc, Disable(Error) is recommended (for advanced users).
'Instead of displaying the error message, it can be written in a file.
msgbox("Error on funcion: "+#ErrorFunction$+" at line: "+#LastErrorLine$)
'Killing Internet Explorer makes the desktop ready for a new execution whatever error occured.

OnAction Error
'To experiment the OnAction Error triggering, change for example a page title in the code
'and it will trigger on a page not found error.
   DoSub process_error

'Reset the timer 1 which is used for measuring the response time

'Maximum elapsed time in hundredth of a second before reporting an error

'Force the exact recognition of the page, as in this example all the page titles start with the same characters

'Start the main url
ret=startbrowser("IE", "")

'click a link
UsePage("WinTask - Welcome")
   ret = ClickHTMLElement("A[INNERTEXT= 'Form']")

'Start the measure
ret=UsePage("WinTask - Form")
'Stop the timer
if timer(1) > tmax_page then
   msgbox("The page took more than "+str$(tmax_page)+" to load")

'On this small example, the result is usually 0 as the page loads immediately.
'On a page which loads slowly, the message box will contain a non-zero value.
msgbox("The page loaded in: "+str$(timer(1))+" hundredth of a second")
'The result can be too written to an Excel file.