Ejemplo n.º 1
0
  public static final WebClient newWebClient() {
    // Create and initialize WebClient object
    WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
    webClient.setThrowExceptionOnScriptError(false);
    webClient.setRefreshHandler(
        new RefreshHandler() {
          public void handleRefresh(Page page, URL url, int arg) throws IOException {
            System.out.println("handleRefresh");
          }
        });

    return webClient;
  }
  private void ProcessTest(WebTest test) {
    HtmlPage page = null;

    // Orville.LOG().info(String.format("Executing test %s\n", event));

    WebClient webClient = new WebClient();
    webClient.setRefreshHandler(new ThreadedRefreshHandler());
    webClient.getOptions().setJavaScriptEnabled(false);

    try {
      if (test.getMethod().toLowerCase().equals("post")) {
        WebRequest request =
            new WebRequest(UrlUtils.toUrlUnsafe(test.getUrlString()), HttpMethod.POST);

        request.setRequestParameters(new ArrayList<NameValuePair>());

        for (Map.Entry<String, String> entry : test.getPostData().entrySet()) {
          request.getRequestParameters().add(new NameValuePair(entry.getKey(), entry.getValue()));
        }

        page = webClient.getPage(request);
      } else {
        page = webClient.getPage(test.getUrlString());
      }

      ProcessResult(test, page.getWebResponse());

    } catch (FailingHttpStatusCodeException fsc) {
      Orville.LOG()
          .warning(
              String.format(
                  "Failing HTTP Status code caught executing the test command: %s\n",
                  fsc.getMessage()));
    } catch (IOException ioe) {
      Orville.LOG()
          .warning(
              String.format(
                  "IO Exception caught executing the test command: %s\n", ioe.getMessage()));
    }

    webClient.closeAllWindows();
  }