问题
我通过设置配置文件变量尝试了所有可能,但是每次我尝试使用自动化框架下载文件时,firefox中的“保存”对话框仍会出现
正在尝试下载的文件的内容类型是application / csv(对于1个文件,其余代码在下面的代码snipit中提及)
设置-
Firefox版本- 52.8.0(64位)
宝石文件
source 'https://rubygems.org'
gem 'actionpack', '~> 4.2.4', require: false
gem 'activemodel', '~> 4.2.4'
gem 'Ascii85'
gem 'browserstack-local'
gem 'cucumber', '< 2.0.0'
gem 'cukeforker'
gem 'cukeforker-webdriver'
gem 'headless'
gem 'httparty'
gem 'json'
gem 'mysql2'
gem 'nokogiri'
gem 'pdf-reader'
gem 'pry'
gem 'rubocop', '~> 0.52.1', require: false
gem 'selenium-webdriver', '3.6.0' # Best practice: keep in sync with hub version
gem 'site_prism'
gem 'uuid'
env.rb
Before do
firefox_profile = Selenium::WebDriver::Firefox::Profile.new
firefox_profile['browser.download.dir'] = ENV['ENV_TEMP_PATH']
firefox_profile['browser.download.folderList'] = 2
firefox_profile['browser.download.panel.shown'] = false
firefox_profile['browser.helperApps.alwaysAsk.force'] = false
firefox_profile['browser.download.manager.showWhenStarting'] = false
firefox_profile['browser.helperApps.neverAsk.openFile'] = 'application/csv, application/octet-stream, text/csv, application/zip, application/pdf, application/xml, application/x-x509-ca-cert'
firefox_profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/csv, application/octet-stream, text/csv, application/zip, application/pdf, application/xml, application/x-x509-ca-cert'
firefox_profile['timeout'] = 480000
firefox_profile['pdfjs.disabled'] = true
firefox_profile['resynchronization_timeout'] = 90
firefox_profile['resynchronize '] = true
firefox_profile['dom.max_chrome_script_run_time'] = 0
firefox_profile['dom.max_script_run_time'] = 0
Capybara.default_selector = :css
Capybara.ignore_hidden_elements = true
Capybara.run_server = false
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 240
Capybara.default_driver = :firefox
Capybara.register_driver :firefox do |app|
Capybara::Selenium::Driver.new(app, browser: :firefox, profile: firefox_profile, marionette: false, http_client: client)
end
end
请注意-
我也尝试过追踪
firefox_profile['browser.helperApps.neverAsk.openFile'] = 'application/csv; application/octet-stream; text/csv; application/zip; application/pdf; application/xml; application/x-x509-ca-cert'
firefox_profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/csv; application/octet-stream; text/csv; application/zip; application/pdf; application/xml; application/x-x509-ca-cert'
在我们的自动化活跃社区中寻求专家的帮助
答案 0 :(得分:1)
为什么要将“ browser.helperApps.neverAsk.openFile”和“ browser.helperApps.neverAsk.saveToDisk”都设置为相同的mime类型?这些设置相互矛盾,因为一种说法是在浏览器中打开这些文件类型,而另一种说法是将它们保存到磁盘(在浏览器中打开优先)。另外-Firefox 52是2年前发布的,可能需要升级。
文件的下载已在Capybaras自己的测试套件中进行了测试,因此您可以在其中看到所需的最小设置(显然可以根据需要调整mime类型)-https://github.com/teamcapybara/capybara/blob/master/spec/selenium_spec_marionette.rb#L13