Skip to content

Commit

Permalink
Increase window-size for headless features tests
Browse files Browse the repository at this point in the history
: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 55321d0)
  • Loading branch information
aaronskiba committed Apr 9, 2024
1 parent 55321d0 commit 708dee4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
11 changes: 1 addition & 10 deletions spec/features/super_admins/merge_org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <button name="button" type="submit" class="btn btn-primary">...</button> is not clickable at point (86, 349).
# Other element would receive the click: <div id="ui-id-2" tabindex="-1" class="ui-menu-item-wrapper">...</div>
# 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:')
Expand Down
11 changes: 1 addition & 10 deletions spec/features/templates/templates_upgrade_customisations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <input type="submit" name="commit" value="Change affiliation" class="btn btn-secondary" data-disable-with="Change affiliation">
# is not clickable at point (101, 203). Other element would receive the click: <div id="ui-id-2" tabindex="-1" class="ui-menu-item-wrapper">...</div>
# 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"
Expand Down
12 changes: 11 additions & 1 deletion spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
# 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
end

# 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

0 comments on commit 708dee4

Please sign in to comment.