From 5b91dc184418000adaabf0dfe64eebbd8233d6ec Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 7 Dec 2023 23:46:20 +0100 Subject: [PATCH] DEV: Set a browser read timeout in capybara (#24757) --- Gemfile | 1 + Gemfile.lock | 3 +++ spec/rails_helper.rb | 4 +++- spec/support/system_helpers.rb | 7 +------ 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 131f0664fd8..d22b3214421 100644 --- a/Gemfile +++ b/Gemfile @@ -128,6 +128,7 @@ group :test do gem "minitest", require: false gem "simplecov", require: false gem "selenium-webdriver", "~> 4.14", require: false + gem "selenium-devtools", require: false gem "test-prof" gem "rails-dom-testing", require: false gem "minio_runner", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 11ab23efea8..cefa9526c26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -461,6 +461,8 @@ GEM google-protobuf (~> 3.23) sass-embedded (1.66.1-x86_64-linux-gnu) google-protobuf (~> 3.23) + selenium-devtools (0.120.0) + selenium-webdriver (~> 4.2) selenium-webdriver (4.16.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) @@ -647,6 +649,7 @@ DEPENDENCIES ruby-readability rubyzip sanitize + selenium-devtools selenium-webdriver (~> 4.14) shoulda-matchers! sidekiq diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index dd83e36b74c..78890e9ff36 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -176,6 +176,7 @@ end RSpec.configure { |config| config.extend Prefabrication } PER_SPEC_TIMEOUT_SECONDS = 30 +BROWSER_READ_TIMEOUT = 30 RSpec.configure do |config| config.fail_fast = ENV["RSPEC_FAIL_FAST"] == "1" @@ -387,7 +388,8 @@ RSpec.configure do |config| options.add_preference("download.default_directory", Downloads::FOLDER) end - driver_options = { browser: :chrome } + client = Selenium::WebDriver::Remote::Http::Default.new(read_timeout: BROWSER_READ_TIMEOUT) + driver_options = { browser: :chrome, http_client: client } if ENV["CAPYBARA_REMOTE_DRIVER_URL"].present? driver_options[:browser] = :remote diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rb index 860325024d4..f7db3707d4d 100644 --- a/spec/support/system_helpers.rb +++ b/spec/support/system_helpers.rb @@ -148,16 +148,11 @@ module SystemHelpers end def using_browser_timezone(timezone, &example) - previous_browser_timezone = ENV["TZ"] - - ENV["TZ"] = timezone - using_session(timezone) do |session| + page.driver.browser.devtools.emulation.set_timezone_override(timezone_id: timezone) freeze_time(&example) session.quit end - - ENV["TZ"] = previous_browser_timezone end # When using parallelism, Capybara's `using_session` method can cause