Forum Discussion

bewen's avatar
bewen
Occasional Contributor
2 years ago

Is there a way to grab webpage loading times in TestComplete?

Hi, im looking to test the loading times of webpages alongside my regular test scenarios and possibly store these loading times into a variable of some sorts to be able to compare later on. Is this possible in TestComplete? Or would I have to use something such as LoadNinja to do this?

 

Thank you for any help!

  • 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.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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.