Is there a way to grab webpage loading times in TestComplete?
- 2 years ago
Hi,
Yes, this is possible if you are not requiring too high precision.
The problem here is that you will need to define when the page is considered to be downloaded.
Regular static web pages can be considered to be downloaded when browser receives response for the page request. In TestComplete this is handled using the .Wait() method.
For example (pseudocode):
aqPerformance.Start('pageLoad', false);
page.ToURL('SomeURL');
page.Wait();
var iLoadTimeMs = aqPerformance.Value('pageLoad');
With modern dynamic web pages the above approach will provide you with the load time for the static content for the requested page. After this content is downloaded, the browser may start to process script code injected to the page which (script code) will start to request additional resources, data, etc..
For such dynamic pages you must either wait until all page scripts finish their execution (sometimes they never finish, for example, if the page endlessly loads some ads) or wait until some specific UI element appears on the page and consider this moment as the indicator for the page been downloaded.
In this case your code will look like this:
aqPerformance.Start('pageLoad', false);
page.ToURL('SomeURL');
page.Wait();
while ( (! pageScriptsCompleted()) && (! timeout()))
Delay(500);
// or
//while ( (! UIElementExists()) && (! timeout()) )
// Delay(500);
var iLoadTimeMs = aqPerformance.Value('pageLoad');
Hope this will help.