Configure a proxy for browser via nodeConfig.json

114 views
Skip to first unread message

jeremyweber

unread,
Mar 3, 2020, 9:40:25 AM3/3/20
to Selenium Users
Hello,

Wondering if its possible to configure a browser to use an external proxy in the nodeConfig.json capabilities section.  So far I have not been able to make this work.

capabilities [ 
{
      "browserName": "chrome",
      "platform": "LINUX",
      "acceptSslCerts": true,
      "javascriptEnabled": true,
      "takesScreenshot": true,
      "maxInstances": 5,
      "cleanSession": true,
      "proxy": {
        "httpProxy": "localhost:8118",
        "proxyType": "manual",
        "sslProxy": "localhost:8118"
       }
}
]

Ive added the above proxy info per ( https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#proxy-json-object ).  But when I issue a test the node log prints out the following:

14:35:48.181 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browser": "chrome",
  "browserName": "chrome",
  "goog:chromeOptions": {
    "args": [
      "--headless",
      "--disable-gpu"
    ],
    "extensions": [
    ]
  },
  "platform": "LINUX"
}

So the above is missing the proxy capability.  When I specify the capability in my code like so:

         Proxy proxy = new Proxy();
         proxy.setHttpProxy("localhost:8118");
         proxy.setSslProxy("localhost:8118");

         DesiredCapabilities caps = new DesiredCapabilities();
         caps.setCapability("browser", "chrome");
         caps.setPlatform(Platform.LINUX);
       //caps.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
         
         ChromeOptions options = new ChromeOptions();
         options.merge(caps);
         options.setHeadless(true);
         options.setCapability(CapabilityType.PROXY, proxy);

I see the following from the node log:

14:38:25.128 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browser": "chrome",
  "browserName": "chrome",
  "goog:chromeOptions": {
    "args": [
      "--headless",
      "--disable-gpu"
    ],
    "extensions": [
    ]
  },
  "platform": "LINUX",
  "proxy": {
    "httpProxy": "localhost:8118",
    "proxyType": "manual",
    "sslProxy": "localhost:8118"
  }
}


So looking for help in understanding if its possible, and if so what I am doing wrong.  

Thanks!


Jeremy

⇜Krishnan Mahadevan⇝

unread,
Mar 9, 2020, 12:32:23 AM3/9/20
to Selenium Users
Jeremy,

To the best of my knowledge, proxy configuration is something that should be set up at the browser level on a per test basis via the desired capabilities. The W3C spec also mentions only this.

I dont think you can setup a proxy server at the node level via the node configuration json file. You can however setup proxy at the JVM level (the node is also a JVM application) using the system properties https://www.baeldung.com/java-connect-via-proxy-server#1-available-system-properties

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1b3cfe9d-5a86-4b0e-969c-32f4ebb04aeb%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages