问题描述
|
我正在使用硒在我的网站上记录一些性能测试。例如登录时间,查询时间等。我在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
类的更多信息。