Protractor: Setting Chrome Options

Created on 22 Oct 2013  路  17Comments  路  Source: angular/protractor

I'd like to add some extensions to my chrome instance, using the WebDriver JavaScript API I would do this:

var options = new chrome.Options().
    addExtensions("pathToExtension");

var driver = new webdriver.Builder().
    withCapabilities(webdriver.Capabilities.chrome()).
    setChromeOptions(options).
    build();

How would I do the same thing in protractor?

It looks like you are parsing the capabilities section of the JSON to work out how to build the driver object, but I don't see anything in the structure that would accept a series of options.

As a side note is there a google group/mailing list for protractor, it would be good to put queries like this there rather than cluttering up the issues list.

needs investigation question

Most helpful comment

Hi! You can set options in the Capabilities object - such as:

capabilities {
  'browserName': 'chrome',
  'chromeOptions': {
    'extensions': ['pathToExtension']
  }
}

All 17 comments

Not seen anything come back on this one.

Is there currently a way in protractor to set options?

Hi! You can set options in the Capabilities object - such as:

capabilities {
  'browserName': 'chrome',
  'chromeOptions': {
    'extensions': ['pathToExtension']
  }
}

Hmm it causes problems for me, if I use:

capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
        'extensions': ['./test/selenium/lib/browser-extensions/chrome/chromevox_1_31_0.crx']
    }
},

I get:

Starting selenium standalone server...
Selenium standalone server started at http://192.168.21.114:49438/wd/hub

/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1542
      throw error;
        ^
UnknownError: unknown error: cannot process extension #1
from unknown error: cannot base64 decode
  (Driver info: chromedriver=2.4.226086,platform=Mac OS X 10.7.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 849 milliseconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'Mili-Collins-MacBook-Air-124.local', ip: '169.254.135.156', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.5', java.version: '1.7.0_06'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at new bot.Error (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
    at Object.bot.response.checkResponse (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
    at /Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:133:24
    at /Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1438:20)
    at notify (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
    at notifyAll (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
    at fulfill (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:402:7)
    at /Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1438:20)
==== async task ====
WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:130:49)
    at Function.webdriver.WebDriver.createSession (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:110:30)
    at Builder.build (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/builder.js:105:20)
    at runJasmineTests (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/lib/runner.js:187:45)
    at /Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1438:20)
    at notify (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
    at notifyAll (/Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
    at /Users/fyre/Programming/vme/vme-checkout-static/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1178:15

If I use:

capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
        //'extensions': ['./test/selenium/lib/browser-extensions/chrome/chromevox_1_31_0.crx']
    }
},

It all works fine:

Starting selenium standalone server...
Selenium standalone server started at http://192.168.21.114:65408/wd/hub
.

Finished in 7.536 seconds
1 test, 1 assertion, 0 failures

Shutting down selenium standalone server.

Tried with a different extension and got the same thing (Just to rule out a problem with this specific extension).

The docs for extensions say: ' Each item in the list should be a base-64 encoded packed Chrome extension '. so, I think it's actually expecting the extension, not the filename.

See also new docs at https://github.com/angular/protractor/blob/master/docs/browser-setup.md, which have links to the chromedriver documentation.

Ah, I was kind of assuming that if you passed it a path chromedriver would read in the file at that path and base 64 encode it.

I'm not sure where to start trying to load a file into JavaScript so I can binary encode it and then base64 encode it. Looks like I'll be having fun tomorrow....

I was facing the similar problem when I tried to test chromiumembedded app (I need to set up chrome binary path).

The solution is set the binary key and also some other keys even there are empty (it is due to that capabilities is pased to the selenium-webdriver/chrome.js):

  capabilities: {
    'browserName': 'chrome',
    "chromeOptions": {
      binary: '/path/to/cef_binary',
      args: [], 
      extensions: [], 
    }   
  },  

...even cleaner solution should be use the Options instance.

Closing as this seems fixed, please open a new issue if you still have extension issues (or ask on stack overflow)

I spend hours looking for documentation on how to do this with webdriverjs. Ended up just looking at the code, which should have been the first thing I looked at:

For those of you trying to figure out how the heck to enable options:
var webdriver = require('selenium-webdriver');
var chromeOptions = webdriver.Capabilities.chrome();
chromeOptions['caps_'].chromeOptions={
args:['--disable-web-security']
};

var driver = new webdriver.Builder().
withCapabilities(chromeOptions).
build();

@Ardesco What was your solution? I'm getting the same error error: cannot base64 decode , but not sure what to do.

chromeOptions: {
      binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome',
      args: [],
      extensions: ['./test/protractor/extension/dist.crx']
}

extensions should contain a list of _base64 encoded extensions_. To do this, you need to encode the contents of your .ctx extension file with base64.

FYI, here is a working solution to the problem.

@juliemr please see the link above - we probably need this example in the protractor examples. Or, even better, would be to make protractor allow to use paths to .crx extensions instead of/as well as base64-encoded extensions. I can participate - just let me know what do you think about it. Thanks.

is there any way to load unpacked extension from a folder?

@intergleam yeah you can use the Chrome CLI flags to pass in a path to a directory which will be loaded. Here I load an extension at the path /dist:

config.capabilities.chromeOptions.args.push("--load-extension=/dist")

The ChromeDriver docs document this approach to loading an unpacked extension.

Hi, i got a problem. Can someome help me !
i want to export file from export button in js page and download file to a directory in my project for testing. But i cant change download default_directory. when i run test, it was downloaded in /Downloads , not /resource/download/ directory.
How can i set download directory for protractor
This is my protractor-config.js

directConnect: true,
multiCapabilities: [{
browserName: 'firefox',
acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: ["--headless" ]
},
prefs: {
'download': {
'prompt_for_download': false,
'default_directory': process.cwd() + "/resources/test/download",
'directory_upgrade': true
},

    },
},
{
  browserName: 'chrome',
  acceptInsecureCerts: true,
  chromeOptions: {
    args: [
      "--headless",    
]
  },
  prefs: {        
        'download': {
            'prompt_for_download': false,                        
            'default_directory': process.cwd() + "/resources/test/download",       
           'directory_upgrade': true,               
        },
    },
}

],
image

I have the same problem, I try to download pdf file in my project path: './artifacts/downloads', but the default download path C:users/downloads is left. And confirmation window for save is appeared although I set 'browser.helperApps.neverAsk.saveToDisk':

capabilities: {
      browserName: 'firefox',
      marionette: true,
      acceptInsecureCerts: true,

      'moz:firefoxOptions': {
        args: [
          //'--headless',
          'window-size=1920,1080'
        ],
            prefs: {
              'browser.download.folderList': 2,
              'browser.download.dir': './artifacts/downloads',
              'services.sync.prefs.sync.browser.download.useDownloadDir': true,
              'browser.download.useDownloadDir': true,
              'browser.download.manager.alertOnEXEOpen': false,
              'browser.download.manager.closeWhenDone': true,
              'browser.download.manager.focusWhenStarting': false,
              'browser.download.manager.showWhenStarting': false,
              'browser.helperApps.alwaysAsk.force': false,
              'browser.download.manager.showAlertOnComplete': false,
              'browser.download.manager.useWindow': false,
              'browser.helperApps.neverAsk.saveToDisk': 'application/x-www-form-urlencoded; gzip,application/pdf; application/csv; application/xlsx; application/xml; image/webp; image/apng; application/signed-exchange',
            }
          }
    },

protractor: 5.4.2

Resolved https://github.com/angular/protractor/issues/175#issuecomment-481584687.
You should delete geckodriver from node_modules and run webdriver-manager update. I noticed prefs didn't work with selenium.standalone 3.4.0

Was this page helpful?
0 / 5 - 0 ratings