0

I am Using a assertTrue statement in the web app testing,even the text is present in the web its returning false. How can I fix this?

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"); 
                                                 }  
   }
Bob Kaufman
  • 12,864
  • 16
  • 78
  • 107

1 Answers1

0

I've given your test a run and It seems to be fine for me however I suspect this is to do with the fact that in here:

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

You don't have any kind of wait, so it will only successfully find "$58,531.06" if the page/result loads quick enough for the test to not bomb out already as it moves to the assertTrue.

I'd suggest using a 'waitForTextPresent' here instead perhaps, or putting something in there to ensure that the test can load the result before you check for it.

Hope that helps.

Dave Goosem
  • 558
  • 8
  • 22