use of com.gargoylesoftware.htmlunit.WebClient in project JSCover by tntim96.
the class HtmlUnitUITest method storeResult.
private static void storeResult() throws IOException {
WebClient webClient = new WebClient();
webClient.getOptions().setTimeout(1000);
HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html?index.html");
page.getHtmlElementById("storeTab").click();
webClient.waitForBackgroundJavaScript(500);
page.getHtmlElementById("storeButton").click();
webClient.waitForBackgroundJavaScript(2000);
String result = page.getElementById("storeDiv").getTextContent();
assertThat(result, containsString("Coverage data stored at target"));
}
use of com.gargoylesoftware.htmlunit.WebClient in project crawler-jsoup-maven by bluetata.
the class htmlunitTest method main.
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
// 屏蔽HtmlUnit等系统 log
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http.client").setLevel(Level.OFF);
String url = "https://www.douyin.com/share/video/6496703951436516621/?mid=6484356820260686606";
System.out.println("Loading page now-----------------------------------------------: " + url);
/* HtmlUnit 模拟浏览器 */
WebClient webClient = new WebClient(BrowserVersion.CHROME);
// 启用JS解释器,默认为true
webClient.getOptions().setJavaScriptEnabled(true);
// 禁用css支持
webClient.getOptions().setCssEnabled(false);
// js运行错误时,是否抛出异常
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
// 设置连接超时时间
webClient.getOptions().setTimeout(10 * 1000);
HtmlPage page = webClient.getPage(url);
// 等待js后台执行30秒
webClient.waitForBackgroundJavaScript(30 * 1000);
String pageAsXml = page.asXml();
/* Jsoup解析处理 */
// Document doc = Jsoup.parse(pageAsXml, "https://bluetata.com/");
Document doc = Jsoup.parse(pageAsXml);
// 获取所有图片元素集
Elements pngs = doc.select("img[src$=.png]");
// 其他操作
System.out.println(doc.toString());
}
use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.
the class Weld1280Test method testELContextOfDepedentScopeBean.
@Test
public void testELContextOfDepedentScopeBean() throws Exception {
WebClient client = new WebClient();
client.setThrowExceptionOnFailingStatusCode(false);
HtmlPage main = client.getPage(url);
assertTrue(main.getBody().asText().contains("Hello from dependent scope bean"));
}
use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.
the class ProbeConfigurationPropertiesTest method testEmbededInfoSnippetNOTAvailable.
@Test
public void testEmbededInfoSnippetNOTAvailable() throws IOException {
WebClient client = new WebClient();
HtmlPage page = client.getPage(url.toString() + "test");
System.out.println(page.getBody().asXml());
assertFalse(page.getBody().asXml().toString().contains("Probe Development Tool"));
assertFalse(page.getBody().asXml().toString().contains(TEST_ARCHIVE_NAME));
assertFalse(page.getBody().asXml().toString().contains("The following snippet was automatically added by Weld"));
}
use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.
the class ProbeConfigurationPropertiesTest method getChildInvocations.
private JsonArray getChildInvocations() throws IOException {
WebClient webClient = invokeSimpleAction(url);
JsonObject invocations = getPageAsJSONObject(INVOCATIONS_PATH, url, webClient);
JsonArray invocationData = invocations.getJsonArray(DATA);
int id = invocationData.getJsonObject(0).getInt(ID);
JsonObject invocationTree = getPageAsJSONObject(INVOCATIONS_PATH + "/" + id, url, webClient);
return invocationTree.getJsonArray(CHILDREN);
}
Aggregations