Hi,
I am using multiCapabilities for multiple browsers in config.js file as below,
multiCapabilities: [
{
'browserName': 'chrome',
'chromeOptions': {
'prefs': {
// disable chrome's annoying password manager
'profile.password_manager_enabled': false,
'credentials_enable_service': false,
'password_manager_enabled': false
}
}
} ,
{
browserName : 'firefox',
marionette : true,
acceptInsecureCerts : true,
firefoxOptions:{
args: ['--headless']
},
'moz:firefoxOptions': {
args: [ '--headless' ]
}
}
]
but instead of executing tests on multiple browsers, I want to make it parameterized like, whatever the browser name I'll pass from command line only that browser should work.
So, is there a way we can pass specific browser name through protractor command line?
You could just use regular capabilities (have a default one may be chrome).. pass a parameter like --browser:chrome or --browser:firefox.. parse these with process.argv and replace the appropriate capability properties. your command line invocation could look something like this
protractor conf.js --browser:chrome
Thanks @raj8github
I didn't understand parse these with process.argv and replace the appropriate capability properties.
Can you please elaborate it or share any useful link which'll give me detail information of it?
I have one more doubt, let's say I also have browser specific parameters which you can see above so what should we do in this case?
Hi @bharukaRupesh, hope this helps https://stackoverflow.com/questions/11580961/sending-command-line-arguments-to-npm-script
@bharukaRupesh
Additionally you could use command-line-args library. It will help you to manage own CLI params and automatically provide you an object with required data. And the command-line-usage library will allow you to make a quick help script to view your CLI params.
@bharukaRupesh very simple example..
you could get more creative with this.. also you can check the browser parameter and populate other capabilities as well..

Let me know if you need more details.
@anihuynh I don't want to send parameters to npm script rather I want to send browser parameter to my config.js file which I used in protractor framework.
Thanks @raj8github
It has worked for me.
May I please know more about process.argv It seems like a global variable .
@bharukaRupesh more info on process.argv can be found here..
https://nodejs.org/docs/latest/api/process.html#process_process_argv
Just run protractor conf.js and console.log(process.argv). you will understand whats happening when you pass any parameters in addition to protractor conf.js those are also captured as part of process.argv and its an array. This holds good for any node js program invocation.
Protractor itself provides few options you could use with "--". Check below. you could try using --browser / --capabilities.* param.

Thanks @raj8github
I think this is well enough information you have provided me. Now, I can understand what's happening behind the scene.
@raj8github How you are handling headless browser option through command line?
Let's say if I want to run my tests in headless firefox or firefox UI or chrome UI then as we have discussed, firefox and chrome UI is working perfectly fine but what if we want to run firefox headless?
@bharukaRupesh as a parameter to your tests, you may pass may be chrome_headless / firefox_headless and when you parse this, build the capability based on the parameter. Again, controlling UI/headless is more of browser capability than protractor one. Refer to below for sample.

When I try the same command from command line, a double quote gets added around capabilities.browseeName and hence command is failing. How to get past that
Most helpful comment
@bharukaRupesh more info on process.argv can be found here..
https://nodejs.org/docs/latest/api/process.html#process_process_argv
Just run
protractor conf.jsandconsole.log(process.argv). you will understand whats happening when you pass any parameters in addition toprotractor conf.jsthose are also captured as part of process.argv and its an array. This holds good for any node js program invocation.Protractor itself provides few options you could use with "--". Check below. you could try using --browser / --capabilities.* param.