1
votes

I want to put a check on response time in page loading when my test runs through multiple pages. If a page doesn't load within 2 seconds, test should fail. I am using Robot Framework with Selenium2Library and everytime I would use command Wait Until Page Contains text 2s, the browser will wait for page to be loaded completely and then run this command which does not serve the purpose. Is it possible to put a timeout on page loading in Robot Framework?

1

1 Answers

0
votes

The default selenium behavior is to wait for the page to be loaded before returning the control (with the exception of some ajax calls done by the js). So in the vanilla Go To navigation call the execution will continue after the load has happened - and thus the Wait Until ... passes almost immediately.
Selenium supports overriding this behavior by settings in the desired_capabilities, but that can be a bit involving (the setting for Firefox is called "pageLoadStrategy", with the values none/eager/normal, for example).

Here's something much easier though - just use a timer, get the timestamps before and after the navigation, and the diff will be the full page load.

${before}=    Get Current Date    result_format=epoch
Go To     https://your-url
${after}=       Get Current Date    result_format=epoch

Should be True    ${after} - ${before} < 2     msg=The total page load time was more than 2 seconds!

The keyword Get Current Date is in the DateTime standard library, and when called with the argument "result_format=epoch" it returns a float (the seconds since 1970) - the fractional part is the milliseconds.
By subtracting the two values you get the full page load time.