ksbg
ksbg

Reputation: 143

Is there any way to pass multiple browser via protractor cli

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.

Upvotes: 7

Views: 3019

Answers (3)

Stiggler
Stiggler

Reputation: 2800

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();
},

Upvotes: 22

hankduan
hankduan

Reputation: 6034

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.

Upvotes: 1

Isaac Lyman
Isaac Lyman

Reputation: 2205

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.

Upvotes: 4

Related Questions