I am trying to configure BrowserMob with sample project to get the Network tab data. But when I run the scripts chrome doesn't loading the site, instead of that showing message saying "There is no internet connection".enter image description here
Any help will be appreciated :)
Below is the configuration:
MacOS: 10.12.6
ChromeBrowser: 61.0.316
Using Gradle to get dependencies:
selenium-java: 3.4.0 selenium-server: 3.4.0 browsermob-core: 2.1.4
Below is the sample code:
// start the proxy
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
// get the Selenium proxy object
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
// start the browser up
System.setProperty("webdriver.chrome.driver", "/Users/abc/Documents/jars/chromedriver");
WebDriver driver = new ChromeDriver(capabilities);
// enable more detailed HAR capture, if desired (see CaptureType for the complete list)
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
// create a new HAR with the label "google.com"
proxy.newHar("google.com");
// open google.com
driver.get("http://www.google.com");
// get the HAR data
Har har = proxy.getHar();
File harFile = new File("/Users/abc/Documents/Sample.har");
try {
har.writeTo(harFile);
} catch (IOException e) {
e.printStackTrace();
}
driver.quit();
Below is data I am getting in .har file.
{"log":{"version":"1.2","creator":{"name":"BrowserMob Proxy","version":"2.1.4","comment":""},"pages":[{"id":"google.com","startedDateTime":"2017-11-06T17:33:42.007Z","title":"google.com","pageTimings":{"comment":""},"comment":""}],"entries":[],"comment":""}}
Import Statements:
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.proxy.CaptureType;