问题
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