本文整理汇总了Java中com.gargoylesoftware.htmlunit.BrowserVersion.BEST_SUPPORTED属性的典型用法代码示例。如果您正苦于以下问题:Java BrowserVersion.BEST_SUPPORTED属性的具体用法?Java BrowserVersion.BEST_SUPPORTED怎么用?Java BrowserVersion.BEST_SUPPORTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.gargoylesoftware.htmlunit.BrowserVersion
的用法示例。
在下文中一共展示了BrowserVersion.BEST_SUPPORTED属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWebClient
/**
* 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;
}
示例2: SessionLoginHelper
/**
* 对于给定登录凭据,使用给定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();
}
示例3: createDriver
@Override
public WebDriver createDriver() throws Exception {
final HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.BEST_SUPPORTED);
driver.setJavascriptEnabled(true);
manage(driver);
return driver;
}
示例4: Browser
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;
}
示例5: test
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();
}
}
示例6: testWeb
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();
}
}
示例7: SuapConnection
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;
}