Defect #44809 ยป 0001-Work-around-session-reset-failures-of-Capybara-with-.patch
| test/application_system_test_case.rb | ||
|---|---|---|
|
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||
|
DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
|
||
|
# Capybara 3.40.0 resets a session by clearing the storage with
|
||
|
# Storage.clearDataForOrigin and the origin "*", but Chrome 158 and later
|
||
|
# reject it. If the reset fails, cookies are kept and the next test starts
|
||
|
# logged in. This workaround has no effect if Capybara does not send the
|
||
|
# origin "*". See https://github.com/teamcapybara/capybara/issues/2865
|
||
|
# TODO: Remove this workaround when a fixed version of Capybara is released.
|
||
|
module ClearStorageWithoutWildcardOrigin
|
||
|
private
|
||
|
def execute_cdp(cmd, params = {})
|
||
|
return super unless cmd == 'Storage.clearDataForOrigin' && params[:origin] == '*'
|
||
|
types = params[:storageTypes].to_s.split(',')
|
||
|
super('Network.clearBrowserCookies') if types.delete('cookies')
|
||
|
origin = ENV['CAPYBARA_APP_HOST'] || Capybara.current_session.server&.base_url
|
||
|
super(cmd, params.merge(origin: origin, storageTypes: types.join(','))) if origin && types.any?
|
||
|
end
|
||
|
end
|
||
|
require 'capybara/selenium/driver'
|
||
|
require 'capybara/selenium/driver_specializations/chrome_driver'
|
||
|
Capybara::Selenium::Driver::ChromeDriver.prepend(ClearStorageWithoutWildcardOrigin)
|
||
|
# Allow running Capybara default server on custom IP address and/or port
|
||
|
Capybara.server_host = ENV['CAPYBARA_SERVER_HOST'] if ENV['CAPYBARA_SERVER_HOST']
|
||
|
Capybara.server_port = ENV['CAPYBARA_SERVER_PORT'] if ENV['CAPYBARA_SERVER_PORT']
|
||