Protractor: Is there a way to specify a proxy server in the Config?

Created on 28 Sep 2013  ·  24Comments  ·  Source: angular/protractor

question

Most helpful comment

capabilities: {
  'proxy': {
    'proxyType': 'manual',
    'httpProxy': 'hostname.com:1234'
  }
}

All 24 comments

Can you show an example of this?

You need to specify it in the capabilities section of the config. Check out this doc for information on how to create the JSON config for webdriver proxies: https://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object

Tried it, didn't really work for me. It could be my inexperience with it. Do you or anyone have a quick example that you can show? It would go a long way.

capabilities: {
  'proxy': {
    'proxyType': 'manual',
    'httpProxy': 'hostname.com:1234'
  }
}

This solution is not working for our setup. Any ideas what I'm doing wrong? I get the following error in the command line when trying to run Protractor:

> Fatal error: protractor exited with code: 1

Here is my config file:

// A reference configuration file.
exports.config = {
   // ----- How to setup Selenium -----
   //
   // There are three ways to specify how to use Selenium. Specify one of the
   // following:
   //
   // 1. seleniumServerJar - to start Selenium Standalone locally.
   // 2. seleniumAddress - to connect to a Selenium server which is already
   //    running.
   // 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.

   // The location of the selenium standalone server .jar file.
   seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
   // The port to start the selenium server on, or null if the server should
   // find its own unused port.
   seleniumPort: null,
   // Chromedriver location is used to help the selenium standalone server
   // find chromedriver. This will be passed to the selenium jar as
   // the system property webdriver.chrome.driver. If null, selenium will
   // attempt to find chromedriver using PATH.
   chromeDriver: './selenium/chromedriver',
   // Additional command line options to pass to selenium. For example,
   // if you need to change the browser timeout, use
   // seleniumArgs: ['-browserTimeout=60'],
   seleniumArgs: [],

   // If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
   // The tests will be run remotely using SauceLabs.
   sauceUser: null,
   sauceKey: null,

   // ----- What tests to run -----
   //
   // Spec patterns are relative to the location of this config.
   specs: [
      './e2e/*-spec.js'
   ],

   // ----- Capabilities to be passed to the webdriver instance ----
   //
   // For a full list of available capabilities, see
   // https://code.google.com/p/selenium/wiki/DesiredCapabilities
   // and
   // https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
   capabilities: {
      'browserName': 'chrome',
      'proxy': {
         'proxyType': 'manual',
         'httpProxy': 'https://localhost.com:8443/'
      }
   },

   // A base URL for your application under test. Calls to protractor.get()
   // with relative paths will be prepended with this.
   baseUrl: 'http://localhost:9999',

   // Selector for the element housing the angular app - this defaults to
   // body, but is necessary if ng-app is on a descendant of <body>
   rootElement: 'body',

   // ----- Options to be passed to minijasminenode -----
   jasmineNodeOpts: {
      // onComplete will be called just before the driver quits.
      onComplete: null,
      // If true, display spec names.
      isVerbose: true,
      // If true, print colors to the terminal.
      showColors: true,
      // If true, include stack traces in failures.
      includeStackTrace: true,
      // Default time to wait in ms before a test fails.
      defaultTimeoutInterval: 10000
   }
};

I tried your capabilities, and it works for me. When I put in a bogus httpProxy I see 'could not connect to proxy' errors in the browser, but the tests still attempt to run. Do your tests run correctly without the proxy? How do they fail in that case?

Okay, what I found does work is to just set the baseurl to the https testing site, like this:

exports.config = {
   seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',

   seleniumPort: null,

   chromeDriver: './selenium/chromedriver',

   seleniumArgs: [],

   sauceUser: null,
   sauceKey: null,

   specs: [
      './e2e/*-spec.js'
   ],

   capabilities: {
      'browserName': 'chrome'
   },

   baseUrl: 'https://localhost:8443/',

   rootElement: 'body',

   jasmineNodeOpts: {
      // onComplete will be called just before the driver quits.
      onComplete: null,
      // If true, display spec names.
      isVerbose: true,
      // If true, print colors to the terminal.
      showColors: true,
      // If true, include stack traces in failures.
      includeStackTrace: true,
      // Default time to wait in ms before a test fails.
      defaultTimeoutInterval: 10000
   }
};

Hi,

I managed to get the proxy working with what you guys have done here so thanks for that, I now want to add in the noProxy variable so that I can exclude my internal services from going to the proxy. I have tried the following but the noProxy part isn't getting used. I am using PhantomJs.

  'proxy': {
      'proxyType': 'manual',
      'httpProxy': 'http://proxy.blah.co.uk:8080'
      'httpsProxy': 'http://proxy.blah.co.uk:8080'
      'noProxy': 'blah.blah.co.uk,*blah.blah.co.uk,.blah.blah.co.uk'
  }

},

Hi,
I could not make it works with an authenticated proxy. I have tried:

'proxy': {
  'proxyType': 'manual',
  'httpProxy': 'user:[email protected]:3128'
  'sslProxy': 'user:[email protected]:3128'
}

and

'proxy': {
  'proxyType': 'manual',
  'httpProxy': 'http://user:[email protected]:3128'
  'sslProxy': 'http://user:[email protected]:3128'
}

I am trying to complete https://docs.angularjs.org/tutorial/step_03, using browser Chrome.

Doesn't work for me either - i have to provide host:port along with username/password and I tried all the above suggestions and nothing seems to be working. However, when I get off the company internet and try without proxy it all works fine. Any help?

Actually, my problem was solved by setting up system variables

 http_proxy   http://user:password@proxy_url:port
 https_proxy   http://user:password@proxy_url:port

This needs to be re-opened, here at GE Software, setting the http_proxy and https_proxy in the configuration still does not allow Protractor to send Saucelabs the final exit code of the test results, making Saucelabs fail the test due to inactivity.

@jonniespratley does protractor config --proxy=http://user:password@proxy_url:port not work for you?

I tried running protractor test on sauce lab but it getting ETIMEDOUT error. I am behind corporate firewall and I have configured proxy in protractor config file and environment variable. Configuration doesn't seems to work. Below is the error I am getting

Error: ETIMEDOUT connect ETIMEDOUT 151.444.33.22:80
    at ClientRequest.<anonymous> (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:174:16)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at Socket.socketErrorListener (_http_client.js:259:9)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1253:8)
    at doNTCallback2 (node.js:439:9)
    at process._tickCallback (node.js:353:17)
From: Task: WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
    at Function.webdriver.WebDriver.createSession (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
    at [object Object].Builder.build (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/selenium-webdriver/builder.js:445:22)
    at [object Object].DriverProvider.getNewDriver (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/lib/driverProviders/driverProvider.js:42:27)
    at [object Object].Runner.createBrowser (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/lib/runner.js:190:37)
    at /Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/lib/runner.js:280:21
    at _fulfilled (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/q/q.js:796:13)
    at /Users/user123/Desktop/Sample/example-sandbox/node_modules/protractor/node_modules/q/q.js:556:49
[launcher] Process exited with error code 1

Any idea? I will really appreciate the help.

I am receiving similar errors. I am behind a corporate proxy and am not able to submit a test to browserstack.

/Users/Documents/coding/sublime/simpleboilerplate/node_modules/selenium-webdriver/lib/promise.js:654
    throw error;
    ^

Error: ETIMEDOUT connect ETIMEDOUT 208.52.180.201:80
    at ClientRequest.<anonymous> (/Users/Documents/coding/sublime/simpleboilerplate/node_modules/selenium-webdriver/http/index.js:381:15)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at Socket.socketErrorListener (_http_client.js:259:9)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1253:8)
    at doNTCallback2 (node.js:441:9)
    at process._tickCallback (node.js:355:17)
From: Task: WebDriver.createSession()
    at Function.createSession (/Users/Documents/coding/sublime/simpleboilerplate/node_modules/selenium-webdriver/lib/webdriver.js:329:24)
    at Builder.build (/Users/Documents/coding/sublime/simpleboilerplate/node_modules/selenium-webdriver/builder.js:458:24)
    at Object.<anonymous> (/Users/Documents/coding/sublime/simpleboilerplate/bs.js:13:3)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3
From: Task: WebDriver.navigate().to(http://www.google.com)
    at WebDriver.schedule (/Users/Documents/coding/sublime/simpleboilerplate/node_modules/selenium-webdriver/lib/webdriver.js:377:17)
    at Navigation.to (/Users/Documents/coding/sublime/simpleboilerplate/node_modules/selenium-webdriver/lib/webdriver.js:1027:25)
    at WebDriver.get (/Users/Documents/coding/sublime/simpleboilerplate/node_modules/selenium-webdriver/lib/webdriver.js:795:28)
    at Object.<anonymous> (/Users/Documents/coding/sublime/simpleboilerplate/bs.js:15:8)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)

What finally worked for us to get out of our corporate proxy and over to perfecto mobile's selenium server was using the webDriverProxy config:

exports.config = {
    framework: 'jasmine',
    seleniumAddress: 'https://yourCloudName.perfectomobile.com/nexperience/perfectomobile/wd/hub',

    webDriverProxy: 'http://your.proxy.here:8080',

    capabilities: { ... },
    specs: ['myspec.js']
};

I am working behind the corporate proxy tried adding this code in conf.js
'proxy': {
'proxyType': 'manual',
'httpProxy': 'user:[email protected]:8080'
'sslProxy': 'user:[email protected]:8080'
}

it was working fine but the application execution time has increased which results failing, Yes I can increase the default time but I dont want my application to take longer time to run.
Can anyone help me to fix this.

Thanks in advance.

@gregjacobs I am using webDriverProxy with perfecto as well. It was working for me for awhile back. After upgrading to 4.x or 5.x, I couldn't get it to work anymore. Does it still work for you after upgrade?

None of the proxy options from https://github.com/angular/protractor/blob/master/lib/config.ts work for me. Anybody had luck configuring proxy in v5 ?

@deli6z
Established BrowserMob proxy and protractor with these capabilities - works fine

  capabilities: {
    'browserName': 'chrome',
    'args': ['disable-web-security'],
    'proxy': {
      'proxyType': 'manual',
      'httpProxy': '10.179.70.127:10801',
      'sslProxy': '10.179.70.127:10801',
      "autodetect": 'false'

    }
}

@gregjacobs I need to specify a username/password for our proxy used on the webDriverProxy property. Do you know how?

@luker2 Unfortunately I'm not exactly sure, but does webDriverProxy: 'http://username:[email protected]:8080' not work? (where 8080 is your proxy's port?)

@gregjacobs yes, I hadn't followed up yet but that's what ended up working!

For others, I also had to url encode the username:password part to escape special characters...

webDriverProxy: `http://${encodeURIComponent(username)}:${encodeURIComponent(password)}@your.proxy.here:8080`

@luker2 Awesome, glad to hear you got it working! And thanks for posting that piece about uri encoding the username and password - good catch!

Was this page helpful?
0 / 5 - 0 ratings