2013-07-01 47 views
1

我有一個需求來測量Web GUI應用程序中不同功能的UI延遲。使用Selenium/TestNG測試UI性能/延遲

例如要測量登錄操作的延遲

1)輸入用戶名,密碼。

2)點擊登錄按鈕

3)測量點擊登錄按鈕,直到登錄操作完成後的時間。

更好的儀器我認爲是Selenium Grid2,Webdriver,TestNG。以下是登錄測試的示例代碼

@Test 
    public void testLogin() throws InterruptedException { 
     wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("username"))).sendKeys("admin"); 
     wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("password"))).sendKeys("admin"); 
    } 

    @Test 
    public void testLoginPerf() throws InterruptedException { 
     webDriver.findElement(By.className("login-button")).click(); 
     wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("logout-button"))); 
    } 

測試運行良好,報告顯示執行的持續時間。

測試testLoginPerf()的執行持續時間是否會給我確切的UI延遲值?有沒有更好的方法來衡量這一點?

回答

1

如果你想多少來衡量時間的用戶界面需要顯示註銷按鈕點擊後做以下的事情:

@Test 
    public void testLoginPerf() throws InterruptedException { 
     webDriver.findElement(By.className("login-button")).click(); 
     long start = System.currentTimeMilis(); 
     wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("logout-button"))); 
     long end = System.currentTimeMilis(); 
     System.out.println("Time: " + (end - start) + " ms); 
    } 

也不要忘記設置sleepInMillis你等待的對象小到足以測量準確。