From 55321d06f1e1dfdae11ff0300d7e55af81ff1369 Mon Sep 17 00:00:00 2001 From: John Pinto Date: Tue, 9 Apr 2024 12:37:25 +0100 Subject: [PATCH 1/2] Fix for failing Rubocop tests. Changes: - To deal with missing favicon.ico error ( ActionController::RoutingError: No route matches [GET] "/favicon.ico") : added config/routes_test.rb to add a route will return an empty response with a 200 OK status code when the browser requests the favicon.ico file. Then for test purposes we add the lines to config/encvironments/test.rb: # Add config/routes_test.rb to routes config.paths['config/routes.rb'] << Rails.root.join('config/routes_test.rb') - The other outstanding errors arose because in the test environment we sometimes encounter errors like (Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: # Element # is not clickable at point (101, 203). Other element would receive the click:
...
). To get round this we use JS to click on element using code like this: change_affiliation_input_button = find('input[value="Change affiliation"]') execute_script('arguments[0].click();', change_affiliation_input_button) --- config/environments/test.rb | 3 +++ config/routes_test.rb | 9 +++++++++ spec/features/super_admins/merge_org_spec.rb | 11 ++++++++++- .../templates_upgrade_customisations_spec.rb | 11 ++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 config/routes_test.rb diff --git a/config/environments/test.rb b/config/environments/test.rb index 7d008cd214..f886d4ada1 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -62,6 +62,9 @@ # config.action_view.annotate_rendered_view_with_filenames = true config.i18n.enforce_available_locales = false + + # Add config/routes_test.rb to routes + config.paths['config/routes.rb'] << Rails.root.join('config/routes_test.rb') end # Used by Rails' routes url_helpers (typically when including a link in an email) diff --git a/config/routes_test.rb b/config/routes_test.rb new file mode 100644 index 0000000000..90555516a2 --- /dev/null +++ b/config/routes_test.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +Rails.application.routes.draw do + # Define your test-specific routes here + + # This route will return an empty response with a 200 OK status code + # when the browser requests the favicon.ico file. + get '/favicon.ico', to: proc { |_env| [200, {}, ['']] } +end diff --git a/spec/features/super_admins/merge_org_spec.rb b/spec/features/super_admins/merge_org_spec.rb index 3e8338655a..29c682f410 100644 --- a/spec/features/super_admins/merge_org_spec.rb +++ b/spec/features/super_admins/merge_org_spec.rb @@ -45,7 +45,16 @@ expect(page).to have_text('Merge Organisations') choose_suggestion('org_org_name', @to_org) - click_button 'Analyze' + # rubocop:disable Layout/LineLength + # Using JS to click on button as click_button 'Analyze' fails due to error like + # Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: + # Element is not clickable at point (86, 349). + # Other element would receive the click:
...
+ # So replacing click_button 'Analyze'with + # rubocop:enable Layout/LineLength + analyze_button = find('button', text: 'Analyze') + execute_script('arguments[0].click();', analyze_button) + # Wait for response sleep(0.3) expect(page).to have_text('Summary:') diff --git a/spec/features/templates/templates_upgrade_customisations_spec.rb b/spec/features/templates/templates_upgrade_customisations_spec.rb index 715691b69c..0fd0121689 100644 --- a/spec/features/templates/templates_upgrade_customisations_spec.rb +++ b/spec/features/templates/templates_upgrade_customisations_spec.rb @@ -52,7 +52,16 @@ # Move to the other funder Org's Templates choose_suggestion('superadmin_user_org_name', funder) - click_button('Change affiliation') + + # rubocop:disable Layout/LineLength + # Using JS to click as click_button "Change affiliation" fails due to error like + # Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: + # Element + # is not clickable at point (101, 203). Other element would receive the click:
...
+ # So replacing click_button('Change affiliation') + # rubocop:enable Layout/LineLength + change_affiliation_input_button = find('input[value="Change affiliation"]') + execute_script('arguments[0].click();', change_affiliation_input_button) # Edit the original Template click_link "#{funder.name} Templates" From 708dee445bb498a029d4daa0be45279844690b27 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Thu, 8 Feb 2024 13:38:30 -0700 Subject: [PATCH 2/2] Increase window-size for headless features tests :selenium_chrome_headless driver has a default window-size of (800x600). This small window-size seems to result in the `Selenium::WebDriver::Error::ElementClickInterceptedError:` This commit increases the window-size and also reverts the prior fix for these errors (commit 55321d06f1e1dfdae11ff0300d7e55af81ff1369) --- spec/features/super_admins/merge_org_spec.rb | 11 +---------- .../templates_upgrade_customisations_spec.rb | 11 +---------- spec/support/capybara.rb | 12 +++++++++++- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/spec/features/super_admins/merge_org_spec.rb b/spec/features/super_admins/merge_org_spec.rb index 29c682f410..3e8338655a 100644 --- a/spec/features/super_admins/merge_org_spec.rb +++ b/spec/features/super_admins/merge_org_spec.rb @@ -45,16 +45,7 @@ expect(page).to have_text('Merge Organisations') choose_suggestion('org_org_name', @to_org) - # rubocop:disable Layout/LineLength - # Using JS to click on button as click_button 'Analyze' fails due to error like - # Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: - # Element is not clickable at point (86, 349). - # Other element would receive the click:
...
- # So replacing click_button 'Analyze'with - # rubocop:enable Layout/LineLength - analyze_button = find('button', text: 'Analyze') - execute_script('arguments[0].click();', analyze_button) - + click_button 'Analyze' # Wait for response sleep(0.3) expect(page).to have_text('Summary:') diff --git a/spec/features/templates/templates_upgrade_customisations_spec.rb b/spec/features/templates/templates_upgrade_customisations_spec.rb index 0fd0121689..715691b69c 100644 --- a/spec/features/templates/templates_upgrade_customisations_spec.rb +++ b/spec/features/templates/templates_upgrade_customisations_spec.rb @@ -52,16 +52,7 @@ # Move to the other funder Org's Templates choose_suggestion('superadmin_user_org_name', funder) - - # rubocop:disable Layout/LineLength - # Using JS to click as click_button "Change affiliation" fails due to error like - # Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: - # Element - # is not clickable at point (101, 203). Other element would receive the click:
...
- # So replacing click_button('Change affiliation') - # rubocop:enable Layout/LineLength - change_affiliation_input_button = find('input[value="Change affiliation"]') - execute_script('arguments[0].click();', change_affiliation_input_button) + click_button('Change affiliation') # Edit the original Template click_link "#{funder.name} Templates" diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index ededee71dd..50f5e42547 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -6,6 +6,16 @@ # Use the fast rack_test driver for non-feature tests by default Capybara.default_driver = :rack_test +# Create a custom driver based on Capybara's :selenium_chrome_headless driver +# This resolves a ElementClickInterceptedError when executing `click_button 'Sign in'` with DMP Assistant +Capybara.register_driver :selenium_chrome_headless_add_window_size do |app| + # Get a copy of the default options for Capybara's :selenium_chrome_headless driver + options = Capybara.drivers[:selenium_chrome_headless].call.options[:options].dup + options.add_argument('--window-size=1920,1080') # default window-size is only (800x600) + # Create a new Selenium driver with the customised options + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) +end + RSpec.configure do |config| config.before(:each, type: :feature, js: false) do Capybara.use_default_driver @@ -13,6 +23,6 @@ # Use the Selenium headless Chrome driver for feature tests config.before(:each, type: :feature, js: true) do - Capybara.current_driver = :selenium_chrome_headless + Capybara.current_driver = :selenium_chrome_headless_add_window_size end end