From 69e1eb034f9714d26b7837b631101d09abbb47d2 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Thu, 15 May 2025 16:26:34 +0200 Subject: [PATCH] Use core's capybara driver configuration Solidus core has migrated to using Firefox for headless testing, which seems to be more stable than Chrome, and uses minimal configuration. See https://github.com/solidusio/solidus/pull/6230 Because older versions of Solidus might not have the new `capybara_driver.rb` file, we still include the legacy code in a `rescue` block. --- lib/solidus_dev_support/rspec/capybara.rb | 38 +++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/solidus_dev_support/rspec/capybara.rb b/lib/solidus_dev_support/rspec/capybara.rb index 2fea86e..eedf5ce 100644 --- a/lib/solidus_dev_support/rspec/capybara.rb +++ b/lib/solidus_dev_support/rspec/capybara.rb @@ -1,28 +1,32 @@ # frozen_string_literal: true -# Allow to override the initial windows size -CAPYBARA_WINDOW_SIZE = ENV.fetch("CAPYBARA_WINDOW_SIZE", "1920x1080").split("x", 2).map(&:to_i) -CAPYBARA_WINDOW_WIDTH = CAPYBARA_WINDOW_SIZE[0] -CAPYBARA_WINDOW_HEIGHT = CAPYBARA_WINDOW_SIZE[1] +begin + require "spree/testing_support/capybara_driver" +rescue LoadError + # Allow to override the initial windows size + CAPYBARA_WINDOW_SIZE = ENV.fetch("CAPYBARA_WINDOW_SIZE", "1920x1080").split("x", 2).map(&:to_i) + CAPYBARA_WINDOW_WIDTH = CAPYBARA_WINDOW_SIZE[0] + CAPYBARA_WINDOW_HEIGHT = CAPYBARA_WINDOW_SIZE[1] -Capybara.javascript_driver = ENV.fetch("CAPYBARA_JAVASCRIPT_DRIVER", "solidus_chrome_headless").to_sym -Capybara.default_max_wait_time = 10 -Capybara.server = :puma, {Silent: true} # A fix for rspec/rspec-rails#1897 + Capybara.javascript_driver = ENV.fetch("CAPYBARA_JAVASCRIPT_DRIVER", "solidus_chrome_headless").to_sym + Capybara.default_max_wait_time = 10 + Capybara.server = :puma, {Silent: true} # A fix for rspec/rspec-rails#1897 -Capybara.drivers[:selenium_chrome_headless].tap do |original_driver| - Capybara.register_driver :solidus_chrome_headless do |app| - original_driver.call(app).tap do |driver| - driver.resize_window_to( - driver.current_window_handle, CAPYBARA_WINDOW_WIDTH, CAPYBARA_WINDOW_HEIGHT - ) + Capybara.drivers[:selenium_chrome_headless].tap do |original_driver| + Capybara.register_driver :solidus_chrome_headless do |app| + original_driver.call(app).tap do |driver| + driver.resize_window_to( + driver.current_window_handle, CAPYBARA_WINDOW_WIDTH, CAPYBARA_WINDOW_HEIGHT + ) + end end end -end -require "capybara-screenshot/rspec" + require "capybara-screenshot/rspec" -Capybara::Screenshot.register_driver(:solidus_chrome_headless) do |driver, path| - driver.browser.save_screenshot(path) + Capybara::Screenshot.register_driver(:solidus_chrome_headless) do |driver, path| + driver.browser.save_screenshot(path) + end end require "spree/testing_support/capybara_ext"