7

Just wanted to know is it possible to specify cli args to protractor like

--multiCapabilities.0.browserName chrome --multiCapabilities.1.browserName firefox

so that it overrides the multiCapabilities defined in protractor conf file.

ksbg
  • 143
  • 2
  • 9

3 Answers3

22

A concrete example of Isaac Lyman's first suggestion:

CLI:

protractor ... --params.browsers="chrome,firefox"

conf.js:

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

  firefox: {
    browserName: 'firefox'
  }
};

...

getMultiCapabilities: function() {
  var browsers = this.params.browsers.split(',');

  // Using lodash to select the keys in `capabilities` corresponding 
  // to the browsers param.
  return _( capabilities )
    .pick(browsers)
    .values()
    .value();
},
Stiggler
  • 2,800
  • 20
  • 21
  • I can't believe you haven't gotten any upvotes for this, it's an excellent solution which works with the current Protractor constraints. One thing to mention is that people will need to "npm install --save-dev lodash" from the command line to add lodash to their node_modules and "var _ = require('lodash');" to import the the library. – John Munsch Jun 02 '15 at 16:47
  • Awesome solution! Thanks. – Ray Dec 05 '18 at 00:48
4

There are a couple of things you could try.

How can I use command line arguments in Angularjs Protractor? explains how to pass in a "params" variable, which if you were totally pro you could reference later in the config file, with the multiCapabilities section (maybe use a helper function or an if statement so you don't have to pass in a complex object from the command line). Not easy to do, but possible.

https://sourcegraph.com/github.com/teerapap/grunt-protractor-runner (see the Options section) is a utility that lets you pass in these things from the command line without any trouble. It's open-source and seems like it would be easy to mod if it doesn't quite meet your needs.

The easiest option, assuming you just need a couple of different options, would just be to use two different config files, "protractor.chrome.conf.js" and "protractor.firefox.conf.js" and run whichever one you need at the moment.

Community
  • 1
  • 1
Isaac Lyman
  • 2,175
  • 1
  • 22
  • 42
1

This is a reasonable request. I've created a PR for this here: https://github.com/angular/protractor/pull/1770. For now, you can patch this PR to your local protractor to use this feature.

hankduan
  • 5,994
  • 1
  • 29
  • 43