Reputation: 216
I am unable to capture request and response using browsermob(selenium+PhantomJS browser)
please refer the sample code
server = new BrowserMobProxyServer();
server.start(0);
server.newHar("contracts");
Capabilities:
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);
launching the application:
driver = new RemoteWebDriver(hubUrl,capabilities);
driver.get("http://www.google.com");
Creating the har file:
Har har = server.getHar();
FileOutputStream fos = new FileOutputStream("runnowNew.har");
har.writeTo(fos);
Har which is generated by using the above code:
{
"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":""
}
}
Upvotes: 1
Views: 971
Reputation: 61
I think the problem is that you don't use BrowserMob Proxy
as a proxy for the Selenium traffic.
You need to set the proxy of Selenium (ip & port) to the one configured in BrowserMob Proxy
.
IP is probably 127.0.0.1
since you work locally, and you can use server.getPort()
to get the port that BrowserMob Proxy
is listening to.
Upvotes: 1