Compiling Browser Objects Made easy



Java Code Examples for com.gargoylesoftware.htmlunit.WebClient

The following are top voted examples for showing how to use com.gargoylesoftware.htmlunit.WebClient. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples. 
Example 1
Project: richfaces   File: SourceChecker.java View source codeVote up6 votes
public void checkComponentSource(URL pageName, String xmlunitPage, By pageElementToTest) throws IOException, SAXException {
    WebClient client = new WebClient();
    client.getOptions().setJavaScriptEnabled(false);

    HtmlPage page = client.getPage(pageName);
    DomElement element;

    String locator = pageElementToTest.toString();
    locator = locator.substring(locator.indexOf(':') + 1).trim();

    if (pageElementToTest instanceof ById) {
        element = page.getElementById(locator);
    } else if (pageElementToTest instanceof ByTagName) {
        element = page.getElementsByTagName(locator).get(0);
    } else {
        throw new IllegalArgumentException("Only id and name are supported");
    }

    String pageCode = element.asXml();

    checkXmlStructure(xmlunitPage, pageCode);
}
 
Example 2
Project: gatein-portal   File: WebHelper.java View source codeVote up6 votes
/**
 * Get HTMLUnit WebClient instance representing the current session.
 *
 * @return WebClient instance representing a browser window
 */
public WebClient getWebClient() {
    if (webClient == null) {
        webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(false);
        webClient.setThrowExceptionOnScriptError(false);

        /*
         * // // all this seems to have no effect on logging //
         *
         * webClient.setHTMLParserListener(new HTMLParserListener() { public void error(String message, URL url, int line,
         * int column, String key) {
         *
         * }
         *
         * public void warning(String message, URL url, int line, int column, String key) {
         *
         * } }); webClient.setIncorrectnessListener(new IncorrectnessListener() { public void notify(String message, Object
         * origin) {
         *
         * } });
         *
         * LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
         * "org.apache.commons.logging.impl.SimpleLog");
         *
         * System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "fatal");
         * System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
         */

        initFromProps();
    }
    return webClient;
}
 
Example 3
Project: mojarra   File: Issue2398IT.java View source codeVote up6 votes
@Before
public void setUp() {
    webUrl = System.getProperty("integration.url");
    webClient = new WebClient();
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.setJavaScriptTimeout(60000);
}
 
Example 4
Project: google-web-toolkit-svnmirror   File: SelectionScriptJavaScriptTest.java View source codeVote up6 votes
/**
 * Load a page and return all alerts that it generates.
 */
private List<String> loadPage(String hostPage, CharSequence testScript)
    throws FailingHttpStatusCodeException, MalformedURLException, IOException {
  WebClient webClient = new WebClient();

  // Make a mock web connection that can return the host page and the test
  // script
  MockWebConnection webConnection = new MockWebConnection();
  webConnection.setDefaultResponse(hostPage, "text/html");
  webConnection.setResponse(new URL(
      "http://foo.test/foo/test.Module.nocache.js"), testScript.toString(),
      "application/javascript");
  webClient.setWebConnection(webConnection);

  final List<String> alerts = new ArrayList<String>();
  webClient.setAlertHandler(new AlertHandler() {
    @Override
    public void handleAlert(Page page, String msg) {
      alerts.add(msg);
    }
  });

  webClient.getPage("http://foo.test/");
  return alerts;
}
 
Example 5
Project: gatein-portal   File: EndToEndTest.java View source codeVote up6 votes
@Override
public void setUp() throws Exception {
    server = new EndToEndServer();
    server.start();

    webClient = new WebClient();
    // NicelyResynchronizingAjaxController changes XHR calls from asynchronous
    // to synchronous, saving the test from needing to wait or sleep for XHR
    // completion.
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    webClient.waitForBackgroundJavaScript(2000);
    webClient.setHTMLParserListener(HTMLParserListener.LOG_REPORTER);
    webClient.setTimeout(3000);

    alertHandler = new CollectingAlertHandler();
    webClient.setAlertHandler(alertHandler);
    token = createToken("canonical", "john.doe");
    language = null;
    server.clearDataServiceError();
}
 
Example 6
Project: elpaaso-core   File: BaseHmlUnit.java View source codeVote up6 votes
@BeforeClass
  public static void setUp() throws InterruptedException {
      log.debug("setUp");
      webClient = new WebClient();
WebClientOptions options = webClient.getOptions();
options.setPrintContentOnFailingStatusCode(true);
options.setJavaScriptEnabled(true);
      webClient.setHTMLParserListener(HTMLParserListener.LOG_REPORTER);
      webClient.setAjaxController(new NicelyResynchronizingAjaxController());
      ProxyConfig proxy = new ProxyConfig("p-goodway.rd.francetelecom.fr", 3128);
      proxy.addHostsToProxyBypass("127.0.0.1");
options.setProxyConfig(proxy);
  }
 
Example 7
Project: Gepard   File: JiraSiteHandler.java View source codeVote up6 votes
/**
 * Constructor of the Jira Site Handler object.
 *
 * @param tc          is the caller test case
 * @param environment provide the Environment object of Gepard, it must contain connectivity info to JIRA.
 */
public JiraSiteHandler(final GepardTestClass tc, final Environment environment) {
    this.environment = environment;
    webClient = new WebClient();
    webClient.getOptions().setJavaScriptEnabled(false);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setUseInsecureSSL(true);

    String phrase = Base64.encode((environment.getProperty(Environment.JIRA_SITE_USERNAME) + ":" + environment.getProperty(Environment.JIRA_SITE_PASSWORD)).getBytes());
    webClient.addRequestHeader("Authorization", "Basic " + phrase);

    try {
        JSONObject serverInfo = getJiraServerInfo();
        String serverTitle = serverInfo.get("serverTitle").toString();
        String version = serverInfo.get("version").toString();
        tc.logComment("Connected to JIRA Server: \"" + serverTitle + "\", version: " + version);
    } catch (FailingHttpStatusCodeException | IOException | JSONException e) {
        throw new SimpleGepardException("Cannot connect to JIRA properly, pls check the settings, reason: " + e.getMessage(), e);
    }
}
 
Example 8
Project: hibiscus.airplus   File: AirPlusSynchronizeJobKontoauszug.java View source codeVote up6 votes
public List<Umsatz> doOneAccount(Konto konto, String username, String password, String firmenname) throws Exception {
 List<Umsatz> umsaetze = new ArrayList<Umsatz>();

 final WebClient webClient = new WebClient();
 webClient.setCssErrorHandler(new SilentCssErrorHandler());
 webClient.setRefreshHandler(new ThreadedRefreshHandler());

 // Login-Page und Login
 HtmlPage page = webClient.getPage("https://portal.airplus.com/airplus/?Language=de&Country=1U");
 //writePage(page, "Login");
 HtmlForm form = page.getForms().get(0);
 form.getInputByName("companyLoginname").setValueAttribute(firmenname);
 form.getInputByName("userLoginname").setValueAttribute(username);
 form.getInputByName("password").setValueAttribute(password);
 List<HtmlElement> submit = form.getElementsByAttribute("input", "type", "image");
 HtmlImageInput x = (HtmlImageInput) submit.get(0);
 page = (HtmlPage) x.click();
 //writePage(page, "NachLogin");
 // > Startseite > Credit Card Management > Online-Kartenkonto
 page = webClient.getPage("https://portal.airplus.com/transaction/transactionStart.do?TKN=1u561.16wa578&__w=1#selected");

 // Suche nach dem passenden Account
 HtmlAnchor link = null;
 for (HtmlAnchor ahref : Utils.getLinks(page)) {
  if (ahref.asText().replace(" ", "").contains(konto.getKundennummer())) {
   link = ahref;
  }
 }
 if (link == null) {
  throw new ApplicationException(i18n.tr("Keine Informationen für Kreditkarte '" + konto.getKundennummer() + "' gefunden!"));
 }
 // Neue Umsätze und Abgerechnete Umsätze fortlaufend abrufen
 for (int i = 0; i < 2; i++) {
  page = link.click();
  TextPage textpage = uebersichtsart(page, pages[i]);
  List<Umsatz> teilUmsaetze = handle(textpage, konto);
  if (i == 0) {
   setzeSaldo(teilUmsaetze, konto);
  }
  umsaetze.addAll(teilUmsaetze);
 }
 // Logout
 webClient.getPage("https://portal.airplus.com/logout.do?TKN=1u561.6fuojg");
 webClient.closeAllWindows();
 return umsaetze;
}
 

Comments

Popular posts from this blog

How whatsapp works

ABOUT WHATSAPP

Edit Java Class file at runtime