1

What I have in my code:

public BrowserMobProxy getProxy() throws UnknownHostException {
    if (proxy == null) {
        proxy = new BrowserMobProxyServer();
        proxy.start(0);
    }
    return proxy;

seleniumProxy = ClientUtil.createSeleniumProxy(getProxy());
caps.setCapability(CapabilityType.PROXY, seleniumProxy);

The problem is running on local its fine but running it on grid(either own or browserstack) it is not working. Is there any way how to make it work - proxy running on local and listening to remote driver?

I tried:

proxy.start(0, InetAddress.getLocalHost());

But without success.

nvldk
  • 115
  • 2
  • 13

2 Answers2

1

I've managed to solve this problem by using standalone browsermob instance and connecting to it via REST api. You can manage remote instance using simple GET/POST/PUT requests as described in REST API section: https://github.com/lightbody/browsermob-proxy

OR you could try and expose your local proxy(but it will be necessary to assigned real address to it) externally and see what is going to happen.

Mikhail
  • 605
  • 4
  • 13
0

I got stuck with the same issue. I use the following stack:

I get it working by the following code (I make bold the key code):

    proxy = new BrowserMobProxyServer();
    proxy.start(0);
    Proxy seleniumProxy = null;    
seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
    String ipAddress = new NetworkUtils().getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    int port = proxy.getPort();
    seleniumProxy.setHttpProxy(ipAddress + ":" + port);
    DesiredCapabilities capability = DesiredCapabilities.chrome();
                    capability.setCapability(CapabilityType.PROXY, seleniumProxy);
                    driver = new RemoteWebDriver(new URL("your_selnium_hub_ip:4444/wd/hub"), capability);
K1RU
  • 1
  • 1
  • Does not work for me, adding the proxy results in the browser displaying `No internet` page – Jezor Nov 20 '18 at 15:50
  • This solution rarely works in CI environments, as the localhost executing BMP (usually GitLab, Bamboo agent etc.) must be accessible from remote browser (typically cloud-deployed). – vacant78 May 21 '20 at 12:47