Reputation: 4328
Issue
I have tried all possibilities by setting profile variables, however the Save dialog in firefox is still appearing every time I try to download a file using my automation framework
Content Type of file which is am trying to download is application/csv (for 1 file, rest are mentioned in below code snipit)
Setup -
Firefox Version - 52.8.0 (64 Bit)
Gemfile
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
Please note -
I have tried following as well
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'
Looking for help from experts in our automation active community
Upvotes: 1
Views: 135
Reputation: 49890
Why are you setting both 'browser.helperApps.neverAsk.openFile' and ''browser.helperApps.neverAsk.saveToDisk' to the same mime types? Those are conflicting settings since one is saying to open those file types in the browser and the other is saying to save them to disk (open in browser takes precedence). Also - Firefox 52 was released 2 years ago, may be time to upgrade.
Downloading of files is tested in Capybaras own test suite so you can see the minimal settings required there (obviously adjust mime types as needed) - https://github.com/teamcapybara/capybara/blob/master/spec/selenium_spec_marionette.rb#L13
Upvotes: 1