1

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

Anand Chavan
  • 4,338
  • 6
  • 23
  • 27

1 Answers1

1

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

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Removed browser.helperApps.neverAsk.openFile - But no luck. It still shows the window. – Anand Chavan Aug 13 '18 at 14:07
  • @AnandChavan Did you try with the latest firefox instead of the 2 year old version (and using marionette rather than the old FirefoxDriver)? Did you try narrowing your profile settings down to the minimum used by Capybaras tests to see if any of the others you're setting are causing the issue? Did you try monitoring the traffic (browser console network tab, etc) to make sure the mime type returned is actually what you think it is? – Thomas Walpole Aug 13 '18 at 17:09
  • I don't have option to upgrade firefox as our VM's are using RHEL7, which is supports FF52 as uppermost version of FF inbuilt. – Anand Chavan Aug 24 '18 at 15:53
  • MIME Types I have checked manually and are as per mentioned in the code. – Anand Chavan Aug 24 '18 at 15:54
  • @AnandChavan If you can't update the version of firefox you may just be out of luck -- it's possible that version is just broken. Note that just because you can't update firefox using yum doesn't mean you can't manually install the latest version of firefox - https://tecadmin.net/install-firefox-on-linux/ – Thomas Walpole Aug 24 '18 at 19:45