本文整理匯總了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;
}