Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to pass multiple browser via protractor cli

Tags:

protractor

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.

like image 713
ksbg Avatar asked Jan 30 '15 15:01

ksbg


People also ask

How do I run multiple browsers on a protractor?

If you would like to test against multiple browsers, use the multiCapabilities configuration option. Protractor will run tests in parallel against each set of capabilities. Please note that if multiCapabilities is defined, the runner will ignore the capabilities configuration.

What browsers are supported by Protractor?

Protractor supports the two latest major versions of Chrome, Firefox, Safari, and IE. These are used in Protractor's own suite of tests.


2 Answers

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();
},
like image 157
Stiggler Avatar answered Sep 28 '22 10:09

Stiggler


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.

like image 35
Isaac Lyman Avatar answered Sep 28 '22 09:09

Isaac Lyman