如何解决硒中的定时页面加载时间
| 我正在使用硒在我的网站上记录一些性能测试。例如登录时间,查询时间等。我在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\" );
解决方法
您的秒表功能应该正常工作。此外,为了让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());
这是有关StopWatch
类的更多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。