Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timing page load times in Selenium

I'm using selenium to log some performance tests on my site. for example login times, query times, etc. I have a sample script recorded on Selenium IDE. I now have it running one Selenium RC (java).

    public void testNew() throws Exception {
    selenium.open("/jira/secure/Dashboard.jspa");
    selenium.selectFrame("gadget-10371");
    selenium.type("login-form-username", "username");
    selenium.type("login-form-password", "pw");
    selenium.click("login");
    selenium.waitForPageToLoad("30000");
    selenium.selectWindow("null");
    selenium.click("find_link");
    selenium.waitForPageToLoad("30000");
    selenium.removeSelection("searcher-pid", "label=All projects");
}

How would I log how long the from clicking the login button to fulling loading the "logged in" screen?

Heres what I came up with, would this be an accurate timing? :

    long starttime = System.currentTimeMillis();
    selenium.waitForPageToLoad("30000");
    long stoptime = System.currentTimeMillis();
    long logintime = stoptime -  starttime;
    System.out.println(logintime+" ms" );
like image 322
ajoe Avatar asked May 24 '11 15:05

ajoe


1 Answers

Your stopwatch function should work. In addition, for Selenium to capture the load time at reasonable precision, reduce the amount of wait time between commands. I, typically, use the following logic -

StopWatch s = new StopWatch();
s.start();
while (selenium.isElementPresent("element_locator")) {
   selenium.setSpeed("10");
   Thread.sleep(10);
}
s.stop();
System.out.println("elapsed time in milliseconds: " + s.getElapsedTime());

Here is some more information on the StopWatch class.

like image 52
rs79 Avatar answered Nov 09 '22 21:11

rs79