Java Code Examples for com.gargoylesoftware.htmlunit.BrowserVersion.BEST_SUPPORTED

The following are Jave code examples for showing how to use BEST_SUPPORTED of the com.gargoylesoftware.htmlunit.BrowserVersion class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Fetchino   File: Util.java   View Source Code Vote up 5 votes
/**
 * Creates a new web client.
 *
 * @return A new {@link WebClient} instance.
 */
public static WebClient createWebClient()
{
	WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
	webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
	webClient.getOptions().setThrowExceptionOnScriptError(false);
	return webClient;
}
 
Example 2
Project: BiliLiveLib   File: SessionLoginHelper.java   View Source Code Vote up 5 votes
/**
 * 对于给定登录凭据,使用给定User-Agent和给定登录超时开始登录会话,且指定是否保持登录。
 * @param email E-Mail/ID/手机号
 * @param password 明文密码
 * @param userAgent User-Agent
 * @param keepLoggingIn 指定是否保持登录
 * @param loginTimeoutMillis 登录执行超时
 * @throws NetworkException 在出现网络问题时抛出
 * @throws IllegalArgumentException 在参数无效时抛出
 * @throws NullPointerException 在有参数为Null时抛出
 */
public SessionLoginHelper(@NotNull String email, @NotNull String password,
                          long loginTimeoutMillis, boolean keepLoggingIn, @NotNull String userAgent)
        throws BiliLiveException {
    this.email = email;
    this.password = password;
    this.loginTimeoutMillis = loginTimeoutMillis;
    this.keepLoggingIn = keepLoggingIn;
    checkArguments(userAgent);

    webClient = new WebClient(BrowserVersion.BEST_SUPPORTED/*, "127.0.0.1", 8888*/); // Commented code is for Fiddler Debugging.
    initWebClient(userAgent);
    startLogin();
}
 
Example 3
Project: alex   File: HtmlUnitDriverConfig.java   View Source Code Vote up 5 votes
@Override
public WebDriver createDriver() throws Exception {
    final HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.BEST_SUPPORTED);
    driver.setJavascriptEnabled(true);
    manage(driver);
    return driver;
}
 
Example 4
Project: stine_calendar_bot   File: Browser.java   View Source Code Vote up 4 votes
public Browser(String startpage, boolean echoPages) throws IOException {

        // Turn off annoying HTMLUnit logging
        java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);

        webclient = new WebClient(BrowserVersion.BEST_SUPPORTED);

        // Initialise browser settings
        webclient.getOptions().setJavaScriptEnabled(true);
        webclient.getOptions().setUseInsecureSSL(true);
        webclient.getCookieManager().setCookiesEnabled(true);

        this.gotoURL(startpage);
        
        this.echoPages = echoPages;
    }
 
Example 5
Project: okserver   File: DigestAuthHandlerTest.java   View Source Code Vote up 4 votes
private void test(final HttpUrl baseUrl) throws Exception {
  final DefaultCredentialsProvider credentials = new DefaultCredentialsProvider();
  final WebClient web = new WebClient(BrowserVersion.BEST_SUPPORTED);
  web.setCredentialsProvider(credentials);
  try {
    final WebClientOptions options = web.getOptions();
    options.setThrowExceptionOnFailingStatusCode(false);
    options.setThrowExceptionOnScriptError(false);
    options.setJavaScriptEnabled(true);
    options.setCssEnabled(true);
    options.setDownloadImages(true);
    options.setRedirectEnabled(true);
    options.setUseInsecureSSL(true);

    final Page page1 = web.getPage(baseUrl.url());
    assertEquals(401, page1.getWebResponse().getStatusCode());
    assertWWWAuthHeaderIsCorrect(
      page1.getWebResponse().getResponseHeaderValue("WWW-AUTHENTICATE"),
      baseUrl.host()
    );

    credentials.addCredentials("anonymous", "anonymous",
                               baseUrl.host(), baseUrl.port(), "[email protected]" + baseUrl.host());

    final Page page2 = web.getPage(baseUrl.url());
    assertEquals(401, page2.getWebResponse().getStatusCode());
    assertWWWAuthHeaderIsCorrect(
      page2.getWebResponse().getResponseHeaderValue("WWW-AUTHENTICATE"),
      baseUrl.host()
    );

    credentials.removeCredentials(new AuthScope(baseUrl.host(), baseUrl.port()));
    credentials.addCredentials("user1", "password1",
                               baseUrl.host(), baseUrl.port(), "[email protected]" + baseUrl.host());

    final Page page3 = web.getPage(baseUrl.url());
    assertEquals(200, page3.getWebResponse().getStatusCode());

    credentials.removeCredentials(new AuthScope(baseUrl.host(), baseUrl.port()));
    credentials.addCredentials("user 2", "password 2",
                               baseUrl.host(), baseUrl.port(), "[email protected]" + baseUrl.host());

    final Page page4 = web.getPage(baseUrl.url());
    assertEquals(200, page4.getWebResponse().getStatusCode());
  }
  finally {
    web.close();
  }
}
 
Example 6
Project: okserver   File: FileHandlerTest.java   View Source Code Vote up 4 votes
static void testWeb(final String baseUrl) throws Exception {
  final File root = getWebRoot();
  //try { Thread.sleep(3000L); } catch (final InterruptedException ignore) {}
  final WebClient web = new WebClient(BrowserVersion.BEST_SUPPORTED);
  try {
    web.setCache(new Cache() {
      @Override
      protected boolean isCacheableContent(WebResponse response) {
        return true;
      }
    });
    final WebClientOptions options = web.getOptions();
    options.setThrowExceptionOnFailingStatusCode(false);
    options.setThrowExceptionOnScriptError(false);
    options.setJavaScriptEnabled(true);
    options.setCssEnabled(true);
    options.setDownloadImages(true);
    options.setRedirectEnabled(false);
    options.setUseInsecureSSL(true);

    final HtmlPage page = web.getPage(baseUrl);
    assertEquals(200, page.getWebResponse().getStatusCode());
    final Cache cache = web.getCache();
    assertEquals(3, cache.getSize());
    final WebResponse imgResponse = cache.getCachedResponse(req(baseUrl + "img.png"));
    assertEquals(200, imgResponse.getStatusCode());
    assertEquals(new File(root, "img.png").length(), imgResponse.getContentLength());
    final WebResponse jsResponse = cache.getCachedResponse(req(baseUrl + "script.js"));
    assertEquals(200, jsResponse.getStatusCode());
    assertEquals(text(new File(root, "script.js")), jsResponse.getContentAsString().trim());
    final WebResponse htmlResponse = cache.getCachedResponse(req(baseUrl));
    assertEquals(200, htmlResponse.getStatusCode());
    assertEquals(text(new File(root, "index.html")), htmlResponse.getContentAsString().trim());

    cache.clear();
    web.getPage(baseUrl + "index.html");
    assertEquals(1, cache.getSize());
    final WebResponse indexResponse = cache.getCachedResponse(req(baseUrl + "index.html"));
    assertEquals(301, indexResponse.getStatusCode());
    assertEquals(baseUrl, indexResponse.getResponseHeaderValue("Location"));
  }
  finally {
    web.close();
  }
}
 
Example 7
Project: SUAPPasswordResetter   File: SuapConnection.java   View Source Code Vote up 3 votes
public SuapConnection(String matricula, String senha) throws Exception {

        //this.removeHtmlUnitWarnings();
        
        conn = new WebClient(BrowserVersion.BEST_SUPPORTED);
        conn.getOptions().setJavaScriptEnabled(false);
        conn.getOptions().setCssEnabled(false);
        conn.getOptions().setAppletEnabled(false);

        this.matricula = matricula;
        this.senha = senha;

    }