Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@earnubs
Last active January 19, 2017 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earnubs/495dae2fd11a361a262e106c477d3e68 to your computer and use it in GitHub Desktop.
Save earnubs/495dae2fd11a361a262e106c477d3e68 to your computer and use it in GitHub Desktop.
Browserstack selenium-webdriver within a proxied environment

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 tunnelling 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()
  .usingServer('https://hub.browserstack.com/wd/hub')
  .withCapabilities({ ... })
  .usingHttpAgent(httpsOverHttp({
    proxy: {
      host: proxyUrl.hostname,
      port: proxyUrl.port
    }
  }))
  .build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment