硒中的定时页面加载时间

问题描述

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...