Search in sources :

Example 96 with CollectingAlertHandler

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;
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) CollectingAlertHandler(com.gargoylesoftware.htmlunit.CollectingAlertHandler) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL)

Aggregations

CollectingAlertHandler (com.gargoylesoftware.htmlunit.CollectingAlertHandler)96 WebClient (com.gargoylesoftware.htmlunit.WebClient)92 ArrayList (java.util.ArrayList)89 Test (org.junit.Test)87 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)82 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)35 URL (java.net.URL)22 Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)20 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)7 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)7 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)6 HashMap (java.util.HashMap)5 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)3 Servlet (javax.servlet.Servlet)3 HttpServlet (javax.servlet.http.HttpServlet)3 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 Page (com.gargoylesoftware.htmlunit.Page)2 ScriptException (com.gargoylesoftware.htmlunit.ScriptException)2 WebWindowEvent (com.gargoylesoftware.htmlunit.WebWindowEvent)2 WebWindowListener (com.gargoylesoftware.htmlunit.WebWindowListener)2