QTP is a functional automated testing tools, and the page loading time or response time of a web application should be a performance testing thing.But as a matter of fact, QTP can also get page load time statistics by some functions. Because QTP using a VBS script and VBS script is so powerful that it can call any windows of the COM components and objects. So the idea of getting page load time is very simple, that is, we want to use VBS for IE page and get statistics of the page load time.
- using createobject to create an instance of IE to access the document object;
- using document object when the page loads readystate properties of various stages of acquisition time,
- using timer () to achieve millisecond statistics.
- in order to facilitate the call, use the time statistics as a function in the code package.
'In loadrunner script to do to access the url parameter, the variable named SITEURL
'timeCount method returns a string, the contents of the string occur at all stages of the statistical time
'You can use various methods view the contents of the result
SiteURL = www.qtp10.com 'Set the URL to visit
result = timeCount (SITEURL) 'returns running results
MsgBox result 'output to run As a result, the line can be commented out loadrunner
'Method defines the beginning
Public Function timeCount (url)
Set dom = CreateObject ( "InternetExplorer.Application") 'Create an IE object
dom.Navigate (url) 'open the specified URL
time_start = Now () 'to obtain statistics at the beginning of time
timer_start = timer () 'Get the current time in milliseconds
'a = dom.ReadyState' Get the current state of the value of IE will be used to determine the value of the state of the current state of the IE
dom.visible = True 'Set IE can be seen
While dom.busy or (dom.readyState <> 4) 'When the IE is in BUSY status or load does not complete (readystate is not equal to 4), depending on the state of IE statistical time, once every millisecond Statistics
wscript.sleep 1 'time interval 1 ms, if the relatively long time interval, then is likely to take less than a state value
Select Case dom.readystate 'to determine the value of dom.readystate
Case 0 'IE is not initialized, in fact, the method, readystate = 0 meaningless, because the cycle is at least a start.
time0 = Now ()
timer0 = timer ()
Case 1 ' "is sending request"
time1 = Now ()
timer1 = timer ()
Case 2 ' "request has been sent to complete"
time2 = Now ()
timer2 = timer ()
Case 3 ' "can receive the part of the response data,"
time3 = Now ()
timer3 = timer ()
Case 4 ' "Page is loaded"
time4 = Now ()
timer4 = timer ()
time_end = Now () 'Statistical End Time
'MsgBox "Start time is:" & time1 & "; the end of time is" & time2
timeCount = "Statistics Start Time:" & start_time & vbcrlf & "time0:" & time0 & vbcrlf & "time1:" & time1 & vbcrlf & "time2:
"& time2 & vbcrlf &" time3: "& time3 & vbcrlf &" time4: "& time4 & vbcrlf &" to complete the initialization of IE and send request:
"& (timer1-timer_start) &" seconds "& vbcrlf &" to send the completion and acceptance of server-side part of the response data:
"& (timer3-timer1) &" seconds "& vbcrlf &" 100% to receive and complete the HTML content parsing:
"& (timer4-timer3) &" seconds "& vbcrlf &" Total spent: "& (timer4-timer_start) &" seconds "