Project

General

Profile

Patch #37558 » 0001r2-Upgrade-webdriver.patch

patch for r22382 - Takashi Kato, 2023-10-26 13:34

View differences:

Gemfile
99 99
  gem "ffi", platforms: [:mingw, :x64_mingw, :mswin]
100 100
  # For running system tests
101 101
  gem 'puma'
102
  gem 'capybara', '~> 3.38.0'
103
  gem "selenium-webdriver", "~> 3.142.7"
104
  gem 'webdrivers', '4.6.1', require: false
102
  gem "capybara", ">= 3.39"
103
  if Gem.ruby_version < Gem::Version.new('3.0')
104
    gem "selenium-webdriver", "<= 4.9.0"
105
    gem "webdrivers", require: false
106
  else
107
    gem "selenium-webdriver", ">= 4.11.0"
108
  end
105 109
  # RuboCop
106 110
  gem 'rubocop', '~> 1.57.0', require: false
107 111
  gem 'rubocop-performance', '~> 1.19.0', require: false
test/application_system_test_case.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
require_relative 'test_helper'
21
require 'webdrivers/chromedriver'
22 21

  
23 22
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
24 23
  DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
25
  GOOGLE_CHROME_OPTS_ARGS = []
26 24

  
27 25
  # Allow running Capybara default server on custom IP address and/or port
28 26
  Capybara.server_host = ENV['CAPYBARA_SERVER_HOST'] if ENV['CAPYBARA_SERVER_HOST']
29 27
  Capybara.server_port = ENV['CAPYBARA_SERVER_PORT'] if ENV['CAPYBARA_SERVER_PORT']
30 28

  
31 29
  # Allow defining Google Chrome options arguments based on a comma-delimited string environment variable
32
  GOOGLE_CHROME_OPTS_ARGS = ENV['GOOGLE_CHROME_OPTS_ARGS'].split(",") if ENV['GOOGLE_CHROME_OPTS_ARGS']
30
  GOOGLE_CHROME_OPTS_ARGS = ENV['GOOGLE_CHROME_OPTS_ARGS'].present? ? ENV['GOOGLE_CHROME_OPTS_ARGS'].split(",") : []
33 31

  
34 32
  options = {}
33
  if ENV['SELENIUM_REMOTE_URL']
34
    options[:url] = ENV['SELENIUM_REMOTE_URL']
35
    options[:browser] = :remote
36
  elsif Gem.ruby_version < Gem::Version.new('3.0')
37
    require 'webdrivers/chromedriver'
38
  end
39

  
35 40
  # Allow running tests using a remote Selenium hub
36
  options[:url] = ENV['SELENIUM_REMOTE_URL'] if ENV['SELENIUM_REMOTE_URL']
37
  options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.chrome(
38
                  'goog:chromeOptions' => {
39
                    'args' => GOOGLE_CHROME_OPTS_ARGS,
40
                    'prefs' => {
41
                      'download.default_directory' => DOWNLOADS_PATH.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR),
42
                      'download.prompt_for_download' => false,
43
                      'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
44
                    }
45
                  }
46
                )
47

  
48
  driven_by(
49
    :selenium, using: :chrome, screen_size: [1024, 900],
50
    options: options
51
  )
41
  driven_by :selenium, using: :chrome, screen_size: [1024, 900], options: options do |driver_option|
42
    GOOGLE_CHROME_OPTS_ARGS.each do |arg|
43
      driver_option.add_argument arg
44
    end
45
    driver_option.add_preference 'download.default_directory',   DOWNLOADS_PATH.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
46
    driver_option.add_preference 'download.prompt_for_download', false
47
    driver_option.add_preference 'plugins.plugins_disabled',     ["Chrome PDF Viewer"]
48
  end
52 49

  
53 50
  setup do
51
    Capybara.app_host = "http://#{Capybara.server_host}:#{Capybara.server_port}"
54 52
    # Allow defining a custom app host (useful when using a remote Selenium hub)
55 53
    if ENV['CAPYBARA_APP_HOST']
56 54
      Capybara.configure do |config|
(3-3/3)