Capabilities and Options in Protractor

In your Protractor conf.js file, we define capabilities object and add information on which browser against Protractor should run the tests.

To run tests against the chrome browser we specify capabilities parameter 'browserName' with Chrome, To use other than Chrome, we simply set a different browser name like Firefox. Know more on DesiredCapabilities

exports.config = {
 //...
 capabilities: {
 'browserName': 'chrome'
 },
 //...
 };

In order to run your tests on multiple browsers, we need to update the protractor config file to support multiple browsers in a test suite by using multiCapabilities configuration option.

With this protractor will run tests in parallel against each set of capabilities. But please note that if multiCapabilities is defined, the runner will ignore the capabilities configuration defined if any.

The multiCapabilities parameter is an array that takes multiple browserName objects for any test suite, as shown below : -

 exports.config = {
 //...
 multiCapabilities: [{
 'browserName': 'chrome'
 }, {
 'browserName': 'firefox'
 }]
 //... };
 

Chrome options are nested in the chromeOptions object. In chromeOptions we have the args entry. With it, we can pass an array of string arguments into Protractor.

For example, Chrome browsers displays a notification bar at the top of the browser saying "Chrome is being controlled by automated test software".

To prevent Chrome from displaying this notification, we pass args "disable-infobars" ChromeOption.

capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'args': ['disable-infobars']
  }
},

We can also pass multiple args to chromeoptions by separating them with a comma like below : -

capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'args': [ '--start-maximized', 'disable-infobars']
  }
},

'--start-maximized' : - Starts the browser maximized, regardless of any previous settings

If you want to run your protractor tests in headless mode
--headless :- Run chrome in headless mode, i.e., without a UI or display server dependencies.

--ignore-certificate-errors : - Ignore If there are any certification errors while running tests.

Check here for the full list of Chrome arguments.

Below is the example of what a conf.js should look like for multicapabilities with both ChromeOptions and FirefoxOptions.

// Capabilities to be passed to the webdriver instance.
  multiCapabilities: [
    {'browserName': 'chrome',
	'chromeOptions': {
    'args': ['disable-infobars']
   }
  },
    {'browserName': 'firefox',
	'moz:firefoxOptions': {
    'args': ['--safe-mode']
  }
	}
  ],

That’s all for now. Hopefully this will help someone who is looking for Capabilities and options in Protractor.

Please do share this.

Protractor Tutorials: 

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.