Skip to content

Commit

Permalink
fix spec regression with capybara/selenium downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperka committed Jan 8, 2025
1 parent 1ceda62 commit 0f77399
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/system/forms/option_set/option_sets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f77399

Please sign in to comment.