use of com.gargoylesoftware.htmlunit.CollectingAlertHandler in project htmlunit by HtmlUnit.
the class GWT250Test method loadGWTPage.
/**
* Loads the GWT unit test index page using the specified test name.
*
* @param testName the test name
* @param collectedAlerts the List to collect alerts into
* @param elementXPath the XPath for an element that is dynamically added to the page.
* if not null than this method waits until this element is there (but max. 30s)
* @throws Exception if an error occurs
* @return the loaded page
*/
protected HtmlPage loadGWTPage(final String testName, final List<String> collectedAlerts, final String elementXPath) throws Exception {
final String resource = "libraries/GWT/" + getDirectory() + "/" + testName + "/" + testName + ".html";
final URL url = getClass().getClassLoader().getResource(resource);
assertNotNull(url);
final WebClient client = getWebClient();
if (collectedAlerts != null) {
client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
}
final HtmlPage page = client.getPage(url);
// wait because the integration build machine is sometimes busy
if (null == elementXPath) {
client.waitForBackgroundJavaScriptStartingBefore(2000);
} else {
final long endTime = System.currentTimeMillis() + 30_000;
while (null == page.getFirstByXPath(elementXPath) && System.currentTimeMillis() < endTime) {
client.waitForBackgroundJavaScriptStartingBefore(1000);
}
}
return page;
}
Aggregations