Using ruby, selenium, capybara, cucumber; Setting local driver in env.rb next way:
args = %w[--ignore-certificate-errors --window-size=1360,998]
prefs = {
download: {
default_directory: "#{Directories::DATA}/downloads",
directory_upgrade: true,
prompt_for_download: false
}}
opts = Selenium::WebDriver::Chrome::Options.new(args: args, prefs: prefs)
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :remote,
url: "http://localhost:9515",
options: opts)
end
chromedriver.log says that correct absolute path has been added to preferences, but test still downloads to default Downloads folder, not the one specified in chromeOptions
[1583876862.576][INFO]: [3d5e8df8f53846b738e383ad9e7642d8] COMMAND InitSession { "capabilities": {
"firstMatch": [ {
"goog:chromeOptions": {
"args": [ "--ignore-certificate-errors", "--window-size=1360,998" ],
"prefs": {
"download": {
"defaultDirectory": "/Users/username/correct/path/data/downloads",
"directoryUpgrade": true,
"promptForDownload": false
}
}
}
} ] }, "desiredCapabilities": {
"browserName": "",
"cssSelectorsEnabled": false,
"javascriptEnabled": false,
"nativeEvents": false,
"platform": "ANY",
"rotatable": false,
"takesScreenshot": false,
"version": "" } } [1583876862.579][INFO]: Populating Preferences file: { "alternate_error_pages": {
"enabled": false }, "autofill": {
"enabled": false }, "browser": {
"check_default_browser": false }, "distribution": {
"import_bookmarks": false,
"import_history": false,
"import_search_engine": false,
"make_chrome_default_for_user": false,
"skip_first_run_ui": true }, "dns_prefetching": {
"enabled": false },
"download": {
"defaultDirectory": "/Users/username/correct/path/data/downloads",
"directoryUpgrade": true,
"promptForDownload": false }, "profile": {
"content_settings": {
"pattern_pairs": {
"https://*,*": {
"media-stream": {
"audio": "Default",
"video": "Default"
...
Recent versions of chromedriver have required setting differently. Easiest solution is to just set all 3 ways like Capybara does in its Chrome tests - https://github.com/teamcapybara/capybara/blob/44621209496fe4dd352709799a0061a80d97d562/spec/selenium_spec_chrome.rb#L13