2012-07-18 49 views
0

我在web應用程序測試中使用assertTrue聲明,即使文本存在於Web中也返回false。我怎樣才能解決這個問題?Selenium RC - 在我的測試腳本出現後出現空指針異常

public void Test1() throws Exception { 
    Selenium selenium = new DefaultSelenium("localhost",1777,"*chrome","http://www.mortgagecalculator.org/"); 
    selenium.start(); 

    try {  
       selenium.open("/"); 
       Thread.sleep(3000); 
       selenium.windowMaximize(); 
        selenium.type("name=param[homevalue]", "400000"); 
      selenium.type("name=param[principal]", "7888800"); 
      selenium.select("name=param[rp]", "label=New Purchase"); 
      selenium.type("name=param[interest_rate]", "8"); 
      selenium.type("name=param[term]", "35"); 
      selenium.select("name=param[start_month]", "label=May"); 
      selenium.select("name=param[start_year]", "label=2006"); 
      selenium.type("name=param[property_tax]", "7.5"); 
      selenium.type("name=param[pmi]", "0.8"); 
      selenium.click("css=input[type=\"submit\"]"); 
      assertTrue(selenium.isTextPresent("$58,531.06")); 
      System.out.println("Assert Statement executed"); 
      selenium.stop(); 
    } 
    catch (Exception e) { 
     System.out.println("In Mortgage Calculator App exception Happened"); 
               } 
    } 

回答

0

我給你的測試運行,它似乎是爲我好,但是我懷疑這是事實,在這裏做:

selenium.click("css=input[type=\"submit\"]"); 
assertTrue(selenium.isTextPresent("$58,531.06")); 

您沒有任何等待,所以如果頁面/結果的加載足夠快,測試不會在它移動到assertTrue時彈出,它將只能成功找到「$ 58,531.06」。

我建議在這裏使用'waitForTextPresent',或者在裏面放一些東西以確保測試可以在檢查之前加載結果。

希望有所幫助。

相關問題