2011-05-24 28 views
6

我正在使用硒在我的網站上記錄一些性能測試。例如登錄時間,查詢時間等。我有一個在Selenium IDE上記錄的示例腳本。我現在運行一個Selenium RC(java)。Selenium中的時間頁面加載時間

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

好問題。我知道在Ruby中使用Watir框架很容易,但我不確定這是否可以在Selenium中使用。嘗試[這個討論](http://stackoverflow.com/questions/4177070/i-want-to-calculate-the-page-load-time-in-watir-or-selenium) – Kyle 2011-05-24 15:31:21

回答

2

你的秒錶功能應該可以工作。另外,Selenium可以以合理的精度捕獲加載時間,減少命令之間的等待時間。 I,典型地,使用下面的邏輯 -

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類的一些更多的信息。