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>");

//For HTTPS

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().
  usingServer('https://hub-cloud.browserstack.com/wd/hub').
  withCapabilities(capabilities).
  usingWebDriverProxy("proxy.org:8080").
  build();


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

HttpCommandExecutor commandExecutor = new HttpCommandExecutor(new Uri("http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub/"), 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:

<configuration>  
  <system.net>  
    <defaultProxy enabled="true">  
      <proxy  
        proxyaddress="http://host:port"  
        bypassonlocal="false"  
      />  
    </defaultProxy>  
  </system.net>  
</configuration>


$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 remote_connection.py 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