How to pass command line arguments to the browser driver being used

孤街浪徒 提交于 2020-01-14 14:30:49

问题


I'm currently using protractor for some tests. Unfortunately, I can't figure out a way to pass command line arguments to the actual driver being used.

For example, chromedriver.exe accepts '--whitelisted-ips' as a command line argument. Is there any way, in my protractor config, that I can pass this to chromedriver.exe?

Another example is, with MicrosoftWebDriver.exe, it has a flag called '--package' which allows me to pass the package id of the app to target. How would I get protractor launch the driver with those arguments?

I thought that maybe I could launch the standalone selenium server with an argument to launch the driver with those arguments, but from my investigation I couldn't find a way to make that happen.

Just to clarify, I'm not asking to pass command line arguments into protractor to use in my tests. I want the browser drivers being that are running (chromedriver.exe, firefoxdriver.exe, MicrosoftWebDriver.exe) to be run with specific command line arguments.


回答1:


Add the arguments to your config file as capabilities. This is a driver-specific property.

For Chrome/Chromedriver:

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['./tmp/specs/*.spec.js'],
    capabilities: {
        'browserName' : 'chrome',
        'goog:chromeOptions' : {
            args: ['--start-maximized']
        }
    }
}

For Firefox/Geckodriver (only changes shown):

capabilities: {
    'browserName' : 'firefox',
    'moz:firefoxOptions' : {
        args: ['-headless']
    }
}

MDN has a (very short) list of vendor-specific capabilities.

See https://sites.google.com/a/chromium.org/chromedriver/capabilities for more.



来源:https://stackoverflow.com/questions/44836077/how-to-pass-command-line-arguments-to-the-browser-driver-being-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!