ajax testing using htmlunit
I am using HtmlUnit for automated testing of my web applica开发者_StackOverflow社区tion that application is not working properly because of asynchronous nature of ajax. I used NicelyResynchronizingAjaxController but it seems it is not working because my application is using multiple threads for retieving data.
Is there any alternative. Thanks in advance.
Try to call.
webClient.waitForBackgroundJavaScript(10000);
or
webClient.waitForBackgroundJavaScriptStartingBefore(10000);
before accessing fields modified via ajax.
If that don't solve try to explicitly wait for a condition that is expected be fulfilled when your JavaScript runs
for (int i = 0; i < 20; i++) {
if (condition_to_happen_after_js_execution) {
break;
}
synchronized (page) {
page.wait(500);
}
}
精彩评论