From: Ruff, T. <Tho...@so...> - 2014-02-07 01:00:22
|
I'm trying to test a GWT application by filling out some input fields and clicking on a button. When I do this in IE or Chrome the outputDiv I'm looking for is modified via AJAX after clicking on the Calculate button but when I run my test case that div is left unmodified (its original text node value is left unchanged). I've tried waitForBackgroundJavaScript(), waitForBackgroundJavaScriptStartingBefore(), wait() and sleep(), but nothing seems to make a difference. Has anyone else been able to succeed in testing GWT pages that modify themselves with the result of AJAX calls? Do you see anything wrong with my test? public class MyTest { @Test public void calcDensityAltitude() throws Exception { WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); HtmlPage page = webClient.getPage("http://mypage"); page.getWebClient().waitForBackgroundJavaScript(10000); try { //set input fields HtmlInput elevation = page.getHtmlElementById("myId"); elevation.setValueAttribute("30.0"); HtmlDivision calButton = page.getFirstByXPath("//*[text()='Calculate']"); page.getWebClient().waitForBackgroundJavaScript(10000); page = calButton.click(); page.getWebClient().waitForBackgroundJavaScript(10000); //try 20 times to wait .5 second each for filling the page. HtmlLabel outputDiv=null; for (int i = 0; i < 20; i++) { outputDiv = page.getFirstByXPath("//*[text()='11422']"); if (null != outputDiv) { break; } synchronized (page) { //also tried to sleep() instead page.wait(500); } } int remainingTasks = page.getWebClient().waitForBackgroundJavaScript(10000); System.out.println("remaining JS tasks: " + remainingTasks); System.out.println(page.asXml()); Assert.assertNotNull(outputDiv); String output = outputDiv.getTextContent(); System.out.println("Desity Altitude: " + output); } catch (...) {...} webClient.closeAllWindows(); } } Thanks, Tom |