0

I am able to create a Selenium proxy using BrowserMob everything work well on my my local PC. When I run the same code on a server (Windows Server 2008 R2 Standard) it errors our "cannot connect to tunnel".

I have tried different combinations of Chrome swithes like --ignore-certificate-errors,--user-data-dir=C:/temp/insecurechrome,--ignore-certificate-errors. I have ensured that .setTrustAllServer(true) is set. I have tried adjusting the Windows Firewal without any effect.

I will add my code I am using, however, it does work on my local PC, yet not on the server. I am hoping someone can suggest other setting on the server I can changer or something in my code I may have missed.

I first get a Chrome Browser message: wating for Proxy Tunnel. Several seconds later (15-20). I get the error: ERR_TUNNEL_CONNECTION_FAILED.

    browserMobProxyServer = new BrowserMobProxyServer(); 
    browserMobProxyServer.setTrustAllServers(true);
    browserMobProxyServer.start(0);
    port = browserMobProxyServer.getPort();
    seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxyServer);

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--proxy-server","--ignore-certificate-errors","--user-data-dir=C:/temp/insecurechrome");

    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("credentials_enable_service", false);
    prefs.put("profile.password_manager_enabled", false);
    options.setExperimentalOption("prefs", prefs);
    PropertyConfigurator.configure("./resources/properties/log4j.properties");
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();

    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
    desiredCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    //desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);  //Has no effect

    driverService = new ChromeDriverService.Builder().usingDriverExecutable(new File("./resources/driver/chromedriver.exe")).usingPort(Integer.parseInt(portRequested)).build();
    driverService.start();
    return new ChromeDriver((ChromeDriverService)driverService, desiredCapabilities);   
R.Nippoldt
  • 11
  • 2
  • Windows Server version have far more strict restrictions compared to a normal PC. You might be facing a firewall related issue or blocked ports. Check for those in Windows Server. Also first get the setup working manually and then check the automation version – Tarun Lalwani Aug 19 '17 at 08:01
  • As a check I have successfully run the BrowserMob proxy (manually) on the Windows 2008 Server. It will take longer to get the access I need to double check the firewall and corporate proxy setup in the Internet options. Thanks for your suggestion so far. – R.Nippoldt Aug 22 '17 at 13:44
  • Do you think setting up and using a certificate in BrowserMob would get around this issue? This is something I might try next. – R.Nippoldt Aug 22 '17 at 13:46

1 Answers1

0

I was able to figure out my own issue. There was an existing corporate proxy that was intercepting the traffic. This proxy has different protocols for servers and for users. When running on my PC it ran fine. When running my program on a server I needed to address proxy forwarding or chaining. I accomplished this by adding the below lines to my above code:

import java.net.InetSocketAddress; ... ...

InetSocketAddress x = new InetSocketAddress("proxy.example.com", 80); browserMobProxyServer.setChainedProxy(x);

R.Nippoldt
  • 11
  • 2