The personal finance app for everyone (by everyone)
Ruby
Keep system-test teardown working on Chrome 158 (#5776)
Yong Cong Sin56559eb9c105
diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rbindex 1c80cf808b..24f305c71c 100644--- a/test/application_system_test_case.rb+++ b/test/application_system_test_case.rb@@ -1,5 +1,6 @@require "test_helper"require "socket"+require_relative "support/capybara_chrome_reset"class ApplicationSystemTestCase < ActionDispatch::SystemTestCaseDEFAULT_VIEWPORT_WIDTH = 1400diff --git a/test/support/capybara_chrome_reset.rb b/test/support/capybara_chrome_reset.rbnew file mode 100644index 0000000000..d42970bb8e--- /dev/null+++ b/test/support/capybara_chrome_reset.rb@@ -0,0 +1,28 @@+require "capybara/selenium/driver"++# Capybara 3.40 ends each Chrome session reset with the DevTools command+# Storage.clearDataForOrigin for the origin "*". Chrome 158 rejects "*" as an+# invalid URL, and the error fails every system test in its teardown. When+# that happens, clear the same data another way: cookies for every site, and+# the other storage types for the origins the tests run on. Browsers that+# still accept "*" never reach the fallback.+module CapybaraChromeResetFallback+ private+ def execute_cdp(cmd, params = {})+ super+ rescue Selenium::WebDriver::Error::InvalidArgumentError+ raise unless cmd == "Storage.clearDataForOrigin" && params[:origin] == "*"++ types = params[:storageTypes].to_s.split(",")+ super("Network.clearBrowserCookies") if types.delete("cookies")+ return if types.empty?++ app_origins.each { |origin| super(cmd, origin: origin, storageTypes: types.join(",")) }+ end++ def app_origins+ [ Capybara.app_host, Capybara.current_session.server&.base_url ].compact.map { |url| URI(url).origin }.uniq+ end+end++Capybara::Selenium::Driver::ChromeDriver.prepend(CapybaraChromeResetFallback)