Selenium-webdriver and HTTP CONNECT tunneling

Boring tunnel machine.

If you are running selenium-webdriver within an environment that requires an HTTPS proxy to connect to the outside world in order to drive your tests, such as when using the Browserstack webdriver hub, then you may need to configure a webdriver proxy with an HTTP CONNECT tunneling httpAgent, like so:

import { Builder } from 'selenium-webdriver';
import { httpsOverHttp } from 'tunnel-agent';
import url from 'url';

# other stuff ...
const proxyUrl = url.parse(process.env.HTTP_PROXY);

driver = new Builder()
  .withCapabilities({ ... })
    proxy: {
      host: proxyUrl.hostname,
      port: proxyUrl.port