2

When I run my test, Firefox downloads the file into the default download directory, USER\Downloads. However, I'm telling it to download into the PROJECT\tmp directory. How do I make it listen to me?

spec/config/capybara.rb
DOWNLOAD_DIRECTORY = Rails.root.join('tmp', 'capybara', 'downloads').to_s

Capybara.register_driver :firefox do |app|
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['devtools.selfxss.count'] = 9999
  profile['browser.download.dir'] = DOWNLOAD_DIRECTORY
  profile['browser.download.folderList'] = 2 # implies custom location
  profile['browser.helperApps.neverAsk.saveToDisk'] =
    'text/csv,text/tsv,text/xml,text/plain,application/pdf,application/doc,application/docx,image/jpeg,application/gzip,application/x-gzip'
  profile.native_events = true
  options = Selenium::WebDriver::Firefox::Options.new
  options.profile = profile
  Capybara::Selenium::Driver.new(
    app,
    browser: :firefox,
    options: options,
    desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox(
      marionette: true
    )
  )
end
part of the feature test
click_on 'CTD_chem_gene_ixn_types.csv'
# Only run for download capable drivers
download_capable do
  wait_until(10) {
    download_present?('CTD_chem_gene_ixn_types.csv')
  }
end

And the error message

 Failure/Error: File.exist?(Rails.root.join('tmp', 'capybara', 'downloads', file))

 Timeout::Error:
   execution expired
 # ./spec/support/feature_support.rb:139:in `download_present?'

Capybara 2.16.1, selenium-webdriver 3.4.4, Firefox 59.0.2

Community
  • 1
  • 1
Chloe
  • 25,162
  • 40
  • 190
  • 357

1 Answers1

1

I had to do the following

  profile['browser.download.dir'] = DOWNLOAD_DIRECTORY
  profile['browser.download.dir'] = DOWNLOAD_DIRECTORY.gsub('/', '\\') if Gem.win_platform?
Chloe
  • 25,162
  • 40
  • 190
  • 357