chromedriver 不使用 download.defaultDirectory



使用红宝石、硒、水豚、黄瓜;在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

相关内容

  • 没有找到相关文章

最新更新