javanoob
javanoob

Reputation: 6410

How to set BrowserMob with WebDriver?

I am trying to intercept the requests made by Webdriver using BrowserMobProxy.

But the below code is not working..It is not able to open the site google.com.

It says the "Internet Explorer cannot open the site"

    proxyServer = new ProxyServer(9101);
    proxyServer.start();

    proxyServer.setCaptureHeaders(true);
    proxyServer.setCaptureContent(true);

    proxyServer.addRequestInterceptor(new RequestInterceptor() {
        @Override
        public void process(BrowserMobHttpRequest request, Har har) {
            System.out.println("From Process method");
        }
    });

    seleniumProxy = proxy.seleniumProxy();

    seleniumProxy.setHttpProxy("localhost:9101");

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    capabilities.setCapability("ie.setProxyByServer", true);

    File file = new File("C:\\path\\IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

    driver = new InternetExplorerDriver(capabilities);
    driver.get("www.google.com");

I get the below error when trying to access google.com from webdrviver

From Process method Nov 09, 2014 2:07:58 AM net.lightbody.bmp.proxy.util.Log info INFO: java.net.UnknownHostException: www.google.com when requesting http://www.google.com/

Upvotes: 1

Views: 2506

Answers (1)

Jason Hoetger
Jason Hoetger

Reputation: 8127

Browsermob uses xbill DNS instead of regular Java/native DNS resolution, which may not play nice with your VPN. The latest browsermob snapshot allows you to enable native DNS fallback by setting the system property bmp.allowNativeDnsFallback to true:

System.setProperty("bmp.allowNativeDnsFallback", "true");
proxyServer = new ProxyServer(9101);
proxyServer.start();

You can get the latest snapshot at the browsermob github page.

Upvotes: 2

Related Questions