I'm trying to programatically test the load time of a list of websites. The purpose is to roughly simulate the page load time a user will perceive.
My first approach is to call the following inside a loop:
startTime = System.currentTimeMillis();
driver.get("http://" + url);
diff = System.currentTimeMillis() - startTime;
System.out.println("Load time was " + diff);
The problem is sometimes I get the time result before the page has really loaded (i.e i get 50ms times) so I guess the control is being handed to the next instruction before the driver.get()
has completed.
What should I do to improve this test?
EDIT:
As user1258245 suggested I could wait for an element to load but the problem is I don't know which pages ill be loading beforehand.