Run Tests Behind Proxy

If your machine is behind a proxy, you won’t be able to connect to BrowserStack’s remote browsers directly. You need to set your proxy settings, so that the connections go through normally. Here is how you do it:

//For HTTP

System.getProperties().put("http.proxyHost", "<HOST>");
System.getProperties().put("http.proxyPort", "<PORT>");
System.getProperties().put("http.proxyUser", "<USER>");
System.getProperties().put("http.proxyPassword", "<PASSWORD>");


System.getProperties().put("https.proxyHost", "<HOST>");
System.getProperties().put("https.proxyPort", "<PORT>");
System.getProperties().put("https.proxyUser", "<USER>");
System.getProperties().put("https.proxyPassword", "<PASSWORD>");

Remember that System.getProperties().put will not change your system properties. It only modifies the Property object within the scope of the running program. Once the program is executed, these properties will no longer be accessible. Hence you need to set these every time your test suite is run.

var driver = new webdriver.Builder().

In case of client bindings v3.10 and above, add the following in your test script:

HttpCommandExecutor commandExecutor = new HttpCommandExecutor(new Uri(""), TimeSpan.FromSeconds(60));
commandExecutor.Proxy = new WebProxy("http://host:port", false);
// add caps, for e.g.
// ChromeOptions options = new ChromeOptions();
// options.AddAdditionalCapability("browser", "Chrome",true);
IWebDriver driver = new RemoteWebDriver(commandExecutor, options.ToCapabilities());

In case of client bindings up to v3.9.1, add the following proxy parameters in your project config file:

    <defaultProxy enabled="true">  

$web_driver = RemoteWebDriver::create(HUB_URL, $capabilities, null, null, PROXY_URL, PROXY_PORT);

Environment variables can’t be used in Python as it doesn’t interpret them, hence it is required to modify the client binding code:

1. Locate the client binding code on your system, that is, search for selenium folder in python/site-packages directory. Refer the link to search for python modules on your system.

2. Navigate to selenium/webdriver/remote/ directory and open file in your editor.

3. Search for code line http = urllib3.PoolManager(timeout=self._timeout) and change it to http = urllib3.ProxyManager('host:port').

ENV['http_proxy'] = 'host:port'
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->proxy(['http'], 'http://localhost:8117');
my $driver = Selenium::Remote::Driver->new('ua'=>$ua);

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked

Thank you for your valuable feedback