Search code examples
seleniumproxyselenium-gridhttp-proxy

Distributed selenium grid and http proxy


I have seen many questions about using Selenium behind proxy where selenium nodes are connecting to internet via proxy. The solution is indicated everywhere is to specify proxy settings in the code when creating the webdriver instance.

Unfortunately in my case this is not going to work, as I am using a distributed selenium grid where different nodes require different proxy settings. When a test is run, the test running only communicates with the grid hub and does not have any control over what node it will run over - thus setting proxy from inside the test is not possible. Each node is a linux machine with both Firefox and Chrome running in virtual framebuffer. Presently the grid has about 25 nodes distributed across multiple data centers, but this number may grow to anywhere up to 1000 in the future.

There are business reasons for such a setup - and I am not in a position (both technically and politically) to change them.

Is there any way to set proxy on a node level and have it apply to everything that's happening on that node only?


Solution

  • Apparently, all I need to do is to define http_proxy and https_proxy environment variables, which chrome will then honour.

    For firefox, proxy parameters can be added to /etc/firefox-$version/pref/firefox.js where $version can be determined by running firefox -v | awk '{print substr($3,1,3)}'.