I was wondering if any one had found a way to toggle between different multiCapabilities configurations coming from a cucumber.conf.js file. Currently I have this one config that will run parallel chrome drivers to run tests.
multiCapabilities: [{
'browserName': 'chrome',
'platform': 'ANY',
shardTestFiles: true,
maxInstances: 2
}],
But what if I also wanted to add a multiCapabilities option for multi browser testing
multiCapabilities: [{
'browserName': 'chrome'
},{
'browserName': 'firefox'
}]
I would rather not want to have to comment out or change code, but rather store a number of multiCapabilities configurations that I can toggle either using something like a flag, tag, or grunt option. Has anyone had any luck with something like this? Thanks!
Your best bet would be to use protractor's in-built command line options for passing browsers or toggling between any such capabilities.
Usage: protractor [configFile] [options]
configFile defaults to protractor.conf.js
The [options] object will override values from the config file.
See the reference config for a full list of options.
Options:
--help Print Protractor help menu
--version Print Protractor version
--browser, --capabilities.browserName Browsername, e.g. chrome or firefox
If you look at the protractor's cli options and if you have more than one browsers setup in your multicapabilties option, you can pass browser names like this -
protractor config.js --capabilities.browserName='chrome'
protractor config.js --capabilities.browserName='firefox'
You can set this as individual scripts in your package.json to run tests in various browsers-
"scripts": {
"tsc": "tsc",
"test": "protractor ./config.js",
"chrome-tests": "protractor ./config.js --capabilities.browserName='chrome'",
"firefox-tests": "protractor ./config.js --capabilities.browserName='firefox'"
}
Now you can invoke this by using npm -
npm run chrome-tests // it would run your tests in chrome browser
npm run firefox-tests // it would run your tests in firefox browser
You can also make use params object in your conf file pass paramaters and access them anywhere in your tests or command line.
params: {
primaryBrowser: 'chrome' // I am biased towards chrome :)
secondaryBrowser: 'firefox'
},
You can access them in your tests by suing browser's global object -
console.log(browser.params.primaryBrowser);
console.log(browser.params.secondaryBrowser);
Similarly you can change them in your command line-
protractor config.js --params.primaryBrowser='firefox'
There is one more elegant way of doing such things through getMultiCapabilities-
You can even pass multiple browsers by accessing the above functions object, please refer this link for more details.
Is there any way to pass multiple browser via protractor cli
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With