コード例 #1
0
  /** @throws Exception if an error occurs */
  @Test
  public void emptyPut() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets =
        new HashMap<String, Class<? extends Servlet>>();
    servlets.put("/test", EmptyPutServlet.class);
    startWebServer("./", null, servlets);

    final String[] expectedAlerts = {"1"};
    final WebClient client = getWebClient();
    client.setAjaxController(new NicelyResynchronizingAjaxController());
    final List<String> collectedAlerts = new ArrayList<String>();
    client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));

    client.getPage("http://localhost:" + PORT + "/test");
    assertEquals(expectedAlerts, collectedAlerts);
  }
コード例 #2
0
  public static WebClient buildWebClient() {
    WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    webClient.getOptions().setCssEnabled(true);
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.getOptions().setUseInsecureSSL(true);

    webClient.setCssErrorHandler(
        new ErrorHandler() {
          @Override
          public void warning(CSSParseException exception) throws CSSException {
            // nothing to do here
          }

          @Override
          public void error(CSSParseException exception) throws CSSException {
            // todo: log or throw exception
          }

          @Override
          public void fatalError(CSSParseException exception) throws CSSException {
            // todo: log or throw exception
          }
        });

    webClient.setIncorrectnessListener(
        new IncorrectnessListener() {
          @Override
          public void notify(String message, Object origin) {
            // todo: analyze and throw exception
          }
        });

    webClient.waitForBackgroundJavaScript(100000);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setRedirectEnabled(true);

    return webClient;
  }