有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Selenium中的java定时页面加载时间

我正在使用selenium在我的网站上记录一些性能测试。例如登录时间、查询时间等。我在Selenium IDE上记录了一个示例脚本。我现在让它运行一个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");
}

我该如何记录从点击登录按钮到完全加载“登录”屏幕的时间

以下是我的想法,这是一个准确的时间吗

    long starttime = System.currentTimeMillis();
    selenium.waitForPageToLoad("30000");
    long stoptime = System.currentTimeMillis();
    long logintime = stoptime -  starttime;
    System.out.println(logintime+" ms" );

共 (1) 个答案

  1. # 1 楼答案

    你的秒表功能应该能用。此外,为了让Selenium以合理的精度捕获加载时间,减少命令之间的等待时间。 一、 通常,使用以下逻辑:

    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是关于StopWatch类的更多信息