在Selenium中计时页面加载时间 [英] Timing page load times in Selenium

查看:1167
本文介绍了在Selenium中计时页面加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用selenium在我的网站上记录一些性能测试。例如登录时间,查询时间等。我在Selenium IDE上记录了一个示例脚本。我现在让它运行一个Selenium RC(java)。

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" );


推荐答案

你的秒表功能应该有效。此外,Selenium以合理的精度捕获加载时间,减少命令之间的等待时间。
我通常使用以下逻辑 -

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());

这里是关于 StopWatch 类的更多信息。

Here is some more information on the StopWatch class.

这篇关于在Selenium中计时页面加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆