【问题标题】:Timing page load times in SeleniumSelenium 中的计时页面加载时间
【发布时间】:2011-05-24 15:26:05
【问题描述】:

我正在使用 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" );

【问题讨论】:

  • 好问题。我知道在 Ruby 中使用 Watir 框架很容易做到这一点,但我不确定这在 Selenium 中是否可行。试试this discussion

标签: java performance logging selenium


【解决方案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 类的更多信息。

【讨论】:

    猜你喜欢
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    相关资源
    最近更新 更多