chromedriver 不使用 download.defaultDirectory

chromedriver doesn't make use of download.defaultDirectory

使用ruby、硒、水豚、黄瓜;在 env.rb 中设置本地驱动程序的下一种方式:

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 表示已将正确的绝对路径添加到首选项中,但测试仍会下载到默认的下载文件夹,而不是 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"
               ...

最新版本的 chromedriver 需要不同的设置。最简单的解决方案是像 Capybara 在其 Chrome 测试中那样设置所有 3 种方式 - https://github.com/teamcapybara/capybara/blob/44621209496fe4dd352709799a0061a80d97d562/spec/selenium_spec_chrome.rb#L13