我无法使用 browsermob(selenium+PhantomJS 浏览器)捕获请求和响应
请参考示例代码
server = new BrowserMobProxyServer();
server.start(0);
server.newHar("contracts");
能力:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
new String[] {"--web-security=false", "--ssl-protocol=any",
"--ignore-ssl-errors=yes"});
capabilities.setCapability("takeScreenshot", true);
URL hubUrl = new URL("http://152.188.0.42:5555/wd/hub");
server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
启动应用程序:
driver = new RemoteWebDriver(hubUrl,capabilities);
driver.get("http://www.google.com");
创建 har 文件:
Har har = server.getHar();
FileOutputStream fos = new FileOutputStream("runnowNew.har");
har.writeTo(fos);
使用上述代码生成的har:
{
"log":
{
"version":"1.2",
"creator":{"name":"BrowserMob Proxy","version":"2.1.2","comment":""},
"pages":[{"id":"contracts","startedDateTime":"2016-10-05T12:56:33.460+05:30","title":"contracts","pageTimings":{"comment":""},"comment":""}],
"entries":[],
"comment":""
}
}