From cb46887d2ce60ec7befa4380d3cf01484a0a2dd3 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 6 May 2025 14:48:22 +0200 Subject: [PATCH] Use Firefox for system specs Chrome seems to consistently get updated with new interesting options, and our specs have been sometimes more, and sometimes less flaky with Chrome as the browser that drives our system specs. This change uses the preconfigured `selenium_headless` driver from the Selenium gem, which uses Firefox under the hood. There are a few changes to helpers in the new admin. All of them have to with clicking table cells rather than the underlying table row. This is how real users also interact with the respective page, so I think it's a good change. (cherry picked from commit d5694a14cd87f65999188bdc514b0a6d9ea2570b) --- .../testing_support/feature_helpers.rb | 4 +-- admin/spec/features/products_spec.rb | 2 +- .../spree/testing_support/capybara_driver.rb | 25 +++---------------- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/admin/lib/solidus_admin/testing_support/feature_helpers.rb b/admin/lib/solidus_admin/testing_support/feature_helpers.rb index b34a588e6f5..a5aec18fdd8 100644 --- a/admin/lib/solidus_admin/testing_support/feature_helpers.rb +++ b/admin/lib/solidus_admin/testing_support/feature_helpers.rb @@ -19,11 +19,11 @@ def stub_authorization!(user) end def find_row(text) - find('table tbody tr', text:) + find('table tbody tr td', text:) end def find_row_checkbox(text) - find_row(text).find('td:first-child input[type="checkbox"]') + find('table tbody tr', text:).find('td:first-child input[type="checkbox"]') end def select_row(text) diff --git a/admin/spec/features/products_spec.rb b/admin/spec/features/products_spec.rb index 686d584594a..6efb41af821 100644 --- a/admin/spec/features/products_spec.rb +++ b/admin/spec/features/products_spec.rb @@ -17,7 +17,7 @@ expect(page).to have_content("$19.99") expect(page).to be_axe_clean - find('table tbody tr', text: 'Just a product').click + find_row('Just a product').click expect(page).to have_current_path("/admin/products/just-a-prod") expect(page).to have_content("Manage images") diff --git a/core/lib/spree/testing_support/capybara_driver.rb b/core/lib/spree/testing_support/capybara_driver.rb index 68c0aa2ebb8..3b482afc2da 100644 --- a/core/lib/spree/testing_support/capybara_driver.rb +++ b/core/lib/spree/testing_support/capybara_driver.rb @@ -1,26 +1,9 @@ # frozen_string_literal: true require "selenium/webdriver" +require "capybara-screenshot" -Capybara.register_driver :selenium_chrome_headless do |app| - browser_options = ::Selenium::WebDriver::Chrome::Options.new - browser_options.args << '--headless' - browser_options.args << '--disable-gpu' - browser_options.args << '--no-sandbox' - browser_options.args << '--window-size=1920,1080' - browser_options.args << '--disable-backgrounding-occluded-windows' - Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options) +Capybara::Screenshot.register_driver(:selenium_headless) do |driver, path| + driver.browser.save_screenshot(path) end - -Capybara.register_driver :selenium_chrome_headless_docker_friendly do |app| - browser_options = ::Selenium::WebDriver::Chrome::Options.new - browser_options.args << '--headless' - browser_options.args << '--disable-gpu' - # Sandbox cannot be used inside unprivileged Docker container - browser_options.args << '--no-sandbox' - browser_options.args << '--window-size=1240,1400' - browser_options.args << '--disable-backgrounding-occluded-windows' - Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options) -end - -Capybara.javascript_driver = (ENV['CAPYBARA_DRIVER'] || :selenium_chrome_headless).to_sym +Capybara.javascript_driver = (ENV['CAPYBARA_DRIVER'] || :selenium_headless).to_sym