diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 76f23162f0..3fe1cd240b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,15 +12,14 @@ require "fileutils" require "vcr" -# Automatically downloads chromedriver, which is used use for JS feature specs -# require "webdrivers/chromedriver" - Capybara.register_driver(:selenium_chrome_headless) do |app| options = Selenium::WebDriver::Chrome::Options.new( args: %w[disable-gpu no-sandbox mute-audio] + (ENV["HEADED"] ? [] : ["headless"]), "goog:loggingPrefs" => {browser: "ALL", client: "ALL", driver: "ALL", server: "ALL"} ) + options.add_preference(:download, default_directory: Capybara.save_path.to_s) + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options).tap do |driver| driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(1280, 2048) end @@ -80,6 +79,17 @@ FileUtils.mkdir_p(Rails.root.join("tmp")) end + # Make sure we have a downloads directory for the browser. + config.before(:suite) do + Capybara.save_path = Rails.root.join("tmp/downloads") + FileUtils.mkdir_p(Capybara.save_path) + end + + # Clean up downloads directory. + config.after(:suite) do + FileUtils.rm_rf(Capybara.save_path) + end + # Set up system tests config.before(:each, type: :system) do driven_by(:rack_test) diff --git a/spec/system/forms/option_set/option_sets_spec.rb b/spec/system/forms/option_set/option_sets_spec.rb index fc94ed8395..b32866c04d 100644 --- a/spec/system/forms/option_set/option_sets_spec.rb +++ b/spec/system/forms/option_set/option_sets_spec.rb @@ -64,7 +64,7 @@ click_on("Export") sleep(1) # CI takes time to download and save the file. - export = CSV.open("Foo.csv").read + export = CSV.open("#{Capybara.save_path}/Foo.csv").read expect(export[0][0]).to eq("Id") expect(export[1][1]).to eq("Banana") end