Ruby on rails - Hvordan tvinger jeg Capybara til at downloade til den mappe jeg specificerer og ikke standard download-mappen i Firefox?

Indlæg af Hanne Mølgaard Plasc

Problem



Når jeg kører min test, downloader Firefox filen i standard download-mappen, USERDownloads. Men jeg fortæller det at downloade til PROJECT mp biblioteket. Hvordan laver jeg det til at lytte til mig?


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


Og fejlmeddelelsen


 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

Bedste reference


Jeg var nødt til at gøre følgende


  profile['browser.download.dir'] = DOWNLOAD\_DIRECTORY
  profile['browser.download.dir'] = DOWNLOAD\_DIRECTORY.gsub('/', '\') if Gem.win\_platform?