0

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;
  • Could you show what you are importing in this class. My guess is something wrong is being imported. Currently I just tried out your code and it worked fine. Tried to break with some common issues and it was working. – Madis Kangro Nov 06 '17 at 20:10
  • @MadisKangro Thanks for reply, I have added the import statements. – Sachin Dhingra Nov 07 '17 at 04:03
  • Same issue here I get the following error: ERR_EMPTY_RESPONSE – Elsid Nov 08 '17 at 01:46

3 Answers3

0

Fixed Double Check your POM I was a version behind 2.1.4 with browser mob, changed to this: I see you are using Gradle on GitHub they are on 2.1.5.

<dependency>
        <groupId>net.lightbody.bmp</groupId>
        <artifactId>browsermob-core</artifactId>
        <version>2.1.5</version>
        <scope>test</scope>
    </dependency>
Elsid
  • 233
  • 2
  • 9
  • 25
0

Same issue happened to me too . Searched and found the reason to be either the proxy didn't started well or the versions are not proper. Did updated the selenium, chrome and BMP versions . It fixed the issue. Below is the versions I have, Please update chrome installations too.

Chrome Driver

        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.4.0</version>

Browser Mob

        <groupId>net.lightbody.bmp</groupId>
        <artifactId>browsermob-core</artifactId>
        <version>2.1.5</version>

Selenium Version

        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.7.1</version>

This should solve your issue .

SurajSr
  • 103
  • 9
0
BrowserMobProxy proxyBrowser = new BrowserMobProxyServer();
    proxyBrowser.start(0);
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyBrowser);

    seleniumProxy.setHttpProxy("localhost:"+proxyBrowser.getPort());
    seleniumProxy.setSslProxy("localhost:"+proxyBrowser.getPort());

This worked for me.