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.
Copy
// 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");
Copy
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'
Copy
const { Builder } = require('selenium-webdriver');
const { HttpClient } = require('selenium-webdriver/http');
const { Agent } = require('https-proxy-agent');
const proxyAgent = new Agent('http://proxy.example.com:8080');
const client = new HttpClient('https://hub.testingbot.com/wd/hub', proxyAgent);
const driver = new Builder()
.usingHttpAgent(proxyAgent)
.usingServer('https://hub.testingbot.com/wd/hub')
.withCapabilities(capabilities)
.build();
Copy
# 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'
Copy
$proxyHost = 'proxy.example.com';
$proxyPort = 8080;
$driver = RemoteWebDriver::create(
'https://hub.testingbot.com/wd/hub',
$caps,
120000, // connection timeout
120000, // request timeout
$proxyHost,
$proxyPort
);
Copy
var proxy = new WebProxy("http://proxy.example.com:8080", false);
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);