From 89b0e83f9bfb4bc554a8d0dc3065c8adab2902ba Mon Sep 17 00:00:00 2001 From: Takashi Kato Date: Wed, 3 Aug 2022 10:11:04 +0000 Subject: [PATCH] Upgrade webdrivers --- Gemfile | 4 ++-- test/application_system_test_case.rb | 22 +++++++++++++++++++--- test/system/issues_test.rb | 14 ++++++++++---- test/system/timelog_test.rb | 8 +++++--- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 6c1e99514..c243ac87c 100644 --- a/Gemfile +++ b/Gemfile @@ -97,8 +97,8 @@ group :test do # For running system tests gem 'puma' gem 'capybara', '~> 3.36.0' - gem "selenium-webdriver", "~> 3.142.7" - gem 'webdrivers', '4.6.1', require: false + gem "selenium-webdriver", Gem.ruby_version < Gem::Version.new('2.7') ? "4.1.0" : "~> 4.3.0" + gem 'webdrivers', '~> 5.0.0', require: false # RuboCop gem 'rubocop', '~> 1.33.0' gem 'rubocop-performance', '~> 1.14.2' diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index d813f0ce3..f2c7e32ae 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -18,7 +18,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require File.expand_path('../test_helper', __FILE__) -require 'webdrivers/chromedriver' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads')) @@ -32,9 +31,15 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase GOOGLE_CHROME_OPTS_ARGS = ENV['GOOGLE_CHROME_OPTS_ARGS'].split(",") if ENV['GOOGLE_CHROME_OPTS_ARGS'] options = {} + if ENV['SELENIUM_REMOTE_URL'] + options[:url] = ENV['SELENIUM_REMOTE_URL'] + options[:browser] = :remote + else + require 'webdrivers/chromedriver' + end + # Allow running tests using a remote Selenium hub - options[:url] = ENV['SELENIUM_REMOTE_URL'] if ENV['SELENIUM_REMOTE_URL'] - options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.chrome( + options[:capabilities] = Selenium::WebDriver::Remote::Capabilities.chrome( 'goog:chromeOptions' => { 'args' => GOOGLE_CHROME_OPTS_ARGS, 'prefs' => { @@ -51,6 +56,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase ) setup do + Capybara.app_host = "http://#{Capybara.server_host}:#{Capybara.server_port}" # Allow defining a custom app host (useful when using a remote Selenium hub) if ENV['CAPYBARA_APP_HOST'] Capybara.configure do |config| @@ -87,6 +93,16 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase end end + def finally(timeout = Capybara.default_max_wait_time, start = Time.now) + yield + return + rescue Minitest::Assertion, Capybara::ElementNotFound + raise if Time.now > start + timeout + sleep 0.1 + retry + end + + def clear_downloaded_files FileUtils.rm downloaded_files end diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index c6a763eae..c2423971a 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -442,8 +442,11 @@ class IssuesSystemTest < ApplicationSystemTestCase # wait for ajax response assert page.has_select?('issue_project_id', selected: 'OnlineStore') - submit_buttons = page.all('input[type=submit]') - assert_equal 2, submit_buttons.size + submit_buttons = [] + finally do + submit_buttons = page.all('input[type=submit]') + assert_equal 2, submit_buttons.size + end assert_equal 'Move', submit_buttons[0].value assert_equal 'Move and follow', submit_buttons[1].value @@ -506,8 +509,11 @@ class IssuesSystemTest < ApplicationSystemTestCase # wait for ajax response assert page.has_select?('issue_project_id', selected: 'OnlineStore') - submit_buttons = page.all('input[type=submit]') - assert_equal 2, submit_buttons.size + submit_buttons = [] + finally do + submit_buttons = page.all('input[type=submit]') + assert_equal 2, submit_buttons.size + end assert_equal 'Copy', submit_buttons[0].value assert_equal 'Copy and follow', submit_buttons[1].value page.find('#issue_priority_id').select('High') diff --git a/test/system/timelog_test.rb b/test/system/timelog_test.rb index 1761d10dc..9a5a70757 100644 --- a/test/system/timelog_test.rb +++ b/test/system/timelog_test.rb @@ -41,9 +41,11 @@ class TimelogTest < ApplicationSystemTestCase within 'form#new_time_entry' do select 'eCookbook', :from => 'Project' end - within 'select#time_entry_activity_id' do - assert has_content?('Development') - assert !has_content?('Design') + finally do + within 'select#time_entry_activity_id' do + assert has_content?('Development') + assert !has_content?('Design') + end end end -- 2.30.2