2012-07-18 50 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',或者在里面放一些东西以确保测试可以在检查之前加载结果。

希望有所帮助。

相关问题