Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set protractor chromeOptions via command line arguments

I'm trying to set the chromeOptions in my protractor config file via the following command:

protractor conf.js --capabilities.chromeOptions.args.0 start-fullscreen --capabilities.chromeOptions.args.1 display  --capabilities.chromeOptions.args.2 :99

I'm expecting the outcome to look something like this:

...
capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'args': ['start-fullscreen','display',':99']
  }
},
...

When I try running the command however, I get the following error in webdriver

...
Caused by: org.openqa.selenium.WebDriverException: unknown error: cannot parse capability: chromeOptions
from unknown error: cannot parse args
from unknown error: must be a list
...

I'm unsure how to structure my command line arguments such that it produces args as a list, or if the functionality is simply not supported.

Here is a post where someone tries something similar, where the functionality seems to be intentionally left out. However, this post seems to imply that the functionality was recently added.

If it is not possible to set via command line, is there a work around? I need to change the display for every protractor call, maybe it can be done in onPrepare via params (note: params can't be referenced in the conf.js outside of onPrepare).

like image 819
jmorgancusick Avatar asked Aug 04 '16 19:08

jmorgancusick


1 Answers

List of command line arguments to be passed to chromedriver can be constructed by passing multiple --capabilities.chromeOptions.args to protractor. Each should be followed by equal sign and command line argument itself. There is no need to manually specify positions of arguments in args array.

If command line options expects additional argument, its value can be separated from option name using equal sign.

So, in your example, you should use:

protractor conf.js --capabilities.chromeOptions.args="start-fullscreen" --capabilities.chromeOptions.args="display=:99"

It should be noted that WebdriverJS expects chromeOptions[args] to be an array, while passing single command line switch will coerce it to string. This may be worked around by passing additional, invalid command line switch that will be ignored:

# This won't work
protractor conf.js --capabilities.chromeOptions.args="start-fullscreen"
# This works as expected
protractor conf.js --capabilities.chromeOptions.args="start-fullscreen" --capabilities.chromeOptions.args="fake-arg"

That workaround must be used until issue 4050 is resolved (patch is available since March, but it hasn't been merged and released yet).

like image 154
Mirek Długosz Avatar answered Oct 11 '22 21:10

Mirek Długosz