最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set protractor chromeOptions via command line arguments - Stack Overflow

programmeradmin0浏览0评论

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

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

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

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

When I try running the mand 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 mand 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 mand 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).

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

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

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

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

When I try running the mand 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 mand 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 mand 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).

Share Improve this question edited May 23, 2017 at 11:54 CommunityBot 11 silver badge asked Aug 4, 2016 at 19:35 jmorgancusickjmorgancusick 1411 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

List of mand 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 mand line argument itself. There is no need to manually specify positions of arguments in args array.

If mand 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 mand line switch will coerce it to string. This may be worked around by passing additional, invalid mand 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).

发布评论

评论列表(0)

  1. 暂无评论