---
title: Running Selenium Tests from behind a proxy
description: How to run Selenium tests from behind a HTTP proxy.
source_url:
  html: https://testingbot.com/support/web-automate/selenium/proxy
  md: https://testingbot.com/support/web-automate/selenium/proxy.md
---

# Run tests from behind a proxy

If the machine you are using to run tests is behind a proxy, chances are that you won't be able to connect to TestingBot's grid.   
 In this case, you can instruct Selenium to go through your proxy. See the example below.

[Java](https://testingbot.com#) [Python](https://testingbot.com#) [NodeJS](https://testingbot.com#) [Ruby](https://testingbot.com#) [PHP](https://testingbot.com#) [C#](https://testingbot.com#)

```java
// For HTTP
System.getProperties().put("http.proxyHost", "proxy.example.com");
System.getProperties().put("http.proxyPort", "8080");
System.getProperties().put("http.proxyUser", "username");
System.getProperties().put("http.proxyPassword", "password");

// For HTTPS
System.getProperties().put("https.proxyHost", "proxy.example.com");
System.getProperties().put("https.proxyPort", "8080");
System.getProperties().put("https.proxyUser", "username");
System.getProperties().put("https.proxyPassword", "password");
```

```python
import os

# Set proxy environment variables before creating the driver
os.environ['HTTP_PROXY'] = 'http://proxy.example.com:8080'
os.environ['HTTPS_PROXY'] = 'http://proxy.example.com:8080'

# Or with authentication
os.environ['HTTP_PROXY'] = 'http://username:password@proxy.example.com:8080'
os.environ['HTTPS_PROXY'] = 'http://username:password@proxy.example.com:8080'
```

```javascript
const { Builder } = require('selenium-webdriver');
const { HttpsProxyAgent } = require('https-proxy-agent');

const proxyAgent = new HttpsProxyAgent('http://proxy.example.com:8080');

const driver = new Builder()
  .usingHttpAgent(proxyAgent)
  .usingServer('https://hub.testingbot.com/wd/hub')
  .withCapabilities(capabilities)
  .build();
```

```ruby
# Set proxy environment variables
ENV['http_proxy'] = 'http://proxy.example.com:8080'
ENV['https_proxy'] = 'http://proxy.example.com:8080'

# Or with authentication
ENV['http_proxy'] = 'http://username:password@proxy.example.com:8080'
ENV['https_proxy'] = 'http://username:password@proxy.example.com:8080'
```

```php
$proxyHost = 'proxy.example.com';
$proxyPort = 8080;

$driver = RemoteWebDriver::create(
    'https://hub.testingbot.com/wd/hub',
    $caps,
    120000, // connection timeout
    120000, // request timeout
    $proxyHost,
    $proxyPort
);
```

```csharp
var proxy = new WebProxy("proxy.example.com", 8080);
var commandExecutor = new HttpCommandExecutor(
    new Uri("https://hub.testingbot.com/wd/hub"),
    TimeSpan.FromSeconds(60)
);
commandExecutor.Proxy = proxy;

ChromeOptions options = new ChromeOptions();
options.PlatformName = "WIN11";
options.BrowserVersion = "latest";

var tbOptions = new Dictionary<string, object>
{
    ["key"] = "API_KEY",
    ["secret"] = "API_SECRET"
};
options.AddAdditionalOption("tb:options", tbOptions);

IWebDriver driver = new RemoteWebDriver(commandExecutor, options);
```

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new) [Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
