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