6

I have been trying to pass BrowserMob proxy to Sauce Labs with no luck.

Here's what I have tried:

  • Start proxy server

    sh browsermob-proxy -port 9090
    
  • Start proxy

    curl -X POST http://localhost:9090/proxy
    {"port":9091} 
    
  • Start sauce connect, and pass proxy server information

    java -jar Sauce-Connect.jar myname xxxxxx -p localhost:9091
    
  • Run Java Client

    ProxyServer proxyServer = new ProxyServer(9091);
    proxyServer.start();    
    
    Proxy proxy = proxyServer.seleniumProxy();
    DesiredCapabilities capabillities = DesiredCapabilities.firefox();
    capabillities.setCapability(CapabilityType.PROXY, proxy);
    capabillities.setCapability("version", "5");
    capabillities.setCapability("platform", Platform.XP);
    this.driver = new RemoteWebDriver(
            new URL("http://myname:xxxxxx@ondemand.saucelabs.com:80/wd/hub"),
            capabillities);
    

The following post provides a general guide line regarding how to make it work, but I keep getting "The proxy server is refusing connections" error.

Mingyu
  • 26,145
  • 13
  • 50
  • 58

2 Answers2

6

I figured out the answer.

  • Start Sauce Connect, and pass proxy server information

    java -jar Sauce-Connect.jar myname xxxxxx -p localhost:9091
    

    Running the above command will pass all requests to localhost 9091 port, and you may use netcat to confirm.

    nc -l 9091
    
  • Run Java Client

    ProxyServer proxyServer = new ProxyServer(9091);
    proxyServer.start();    
    
    Proxy proxy = proxyServer.seleniumProxy();
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    // DO NOT set proxy for RemoteWebDriver
    // capabilities.setCapability(CapabilityType.PROXY, proxy);
    capabilities.setCapability("version", "5");
    capabilities.setCapability("platform", Platform.XP);
    this.driver = new RemoteWebDriver(
            new URL("http://myname:xxxxxx@ondemand.saucelabs.com:80/wd/hub"),
            capabillities);
    

    The Java Client should starts a proxy at Port 9091. Unlike using FirefoxDriver directly, proxy should not be set in capabilities.

Mingyu
  • 26,145
  • 13
  • 50
  • 58
  • So, it works if you are using 1 thread right? Obviously, this wouldn't work very well with multiple threads. – djangofan May 06 '14 at 17:18
  • @Mingyu I am trying something similar, have one question though! Is it compulsory that the local machine where sauce-conncet is running and the sauce labs VM to be connected to same Network? or does this proxy work even if both local sauce-connect machine and sauce labs VM are present in different geo locations and connected to different Networks – user2649233 Jun 07 '17 at 10:41
0

I could be wrong, but try a different port (like 9090). SauceConnect only proxies some ports for localhost as per the docs

TinyTimZamboni
  • 4,993
  • 2
  • 24
  • 23
  • The port mentioned above is for Proxy Server, which I need to daisy chain `Sauce Connect`. Here's their FAQ: https://saucelabs.com/docs/connect#proxy – Mingyu Feb 12 '14 at 07:27