Skip to content

Commit

Permalink
Bump Selenium requirement to 4.8+ (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole authored Jun 10, 2023
1 parent 6a91f61 commit 0be79d6
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 68 deletions.
2 changes: 1 addition & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Release date: unreleased

* Dropped support for Ruby 2.7, 3.0+ is now required
* Dropped support for Selenium < 4.1
* Dropped support for Selenium < 4.8

# Version 3.39.2
Release date: 2023-06-10
Expand Down
2 changes: 1 addition & 1 deletion capybara.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rubocop-rspec', ['~>2.0'])
s.add_development_dependency('sauce_whisk')
s.add_development_dependency('selenium_statistics')
s.add_development_dependency('selenium-webdriver', ['~>4.1'])
s.add_development_dependency('selenium-webdriver', ['~>4.8'])
s.add_development_dependency('sinatra', ['>= 1.4.0'])
s.add_development_dependency('uglifier')
s.add_development_dependency('yard', ['>= 0.9.0'])
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.base-versions
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ gem 'rack', '~>2.0.0'
gem 'nokogiri', '~>1.11.0'
gem 'xpath', '~>3.2.0'
gem 'rspec', '~>3.5.0'
gem 'selenium-webdriver', '~>4.1.0'
gem 'selenium-webdriver', '~>4.8.0'
gem 'irb', '~>1.1.1'
gem 'webdrivers', '~>5.0.0'
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.edge-firefox
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gemspec path: '..'

gem 'xpath', github: 'teamcapybara/xpath'

gem 'selenium-webdriver', '>= 4.1.0'
gem 'selenium-webdriver', '>= 4.8.0'
gem 'rack', github: 'rack/rack'
gem 'sinatra', github: 'sinatra/sinatra', branch: 'master'

Expand Down
5 changes: 2 additions & 3 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def load_selenium
require 'selenium-webdriver'
require 'capybara/selenium/patches/atoms'
require 'capybara/selenium/patches/is_displayed'
require 'capybara/selenium/patches/action_pauser'

# Look up the version of `selenium-webdriver` to
# see if it's a version we support.
Expand All @@ -42,8 +41,8 @@ def load_selenium
Gem::Version.new(Selenium::WebDriver::VERSION)
end

unless Gem::Requirement.new('>= 4.1').satisfied_by? @selenium_webdriver_version
warn "Warning: You're using an unsupported version of selenium-webdriver, please upgrade."
unless Gem::Requirement.new('>= 4.8').satisfied_by? @selenium_webdriver_version
warn "Warning: You're using an unsupported version of selenium-webdriver, please upgrade to 4.8+."
end

@selenium_webdriver_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@

module Capybara::Selenium::Driver::FirefoxDriver
def self.extended(driver)
driver.extend Capybara::Selenium::Driver::W3CFirefoxDriver if w3c?(driver)
driver.extend Capybara::Selenium::Driver::W3CFirefoxDriver
bridge = driver.send(:bridge)
bridge.extend Capybara::Selenium::IsDisplayed unless bridge.send(:commands, :is_element_displayed)
end

def self.w3c?(driver)
(defined?(Selenium::WebDriver::VERSION) && (Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('4'))) ||
driver.browser.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
end
end

module Capybara::Selenium::Driver::W3CFirefoxDriver
Expand Down
29 changes: 4 additions & 25 deletions lib/capybara/selenium/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,11 @@ def right_click(keys = [], **options)
target = click_options.coords? ? nil : native
if click_options.delay.zero?
action.context_click(target)
elsif w3c?
else
action.move_to(target) if target
action.pointer_down(:right).then do |act|
action_pause(act, click_options.delay)
end.pointer_up(:right)
else
raise ArgumentError, 'Delay is not supported when right clicking with legacy (non-w3c) selenium driver'
end
end
end
Expand Down Expand Up @@ -414,21 +412,15 @@ def action_with_modifiers(click_options)
actions = browser_action.tap do |acts|
if click_options.coords?
if click_options.center_offset?
if Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('4.3')
acts.move_to(native, *click_options.coords)
else
acts.move_to(native).move_by(*click_options.coords)
end
elsif Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('4.3')
acts.move_to(native, *click_options.coords)
else
right_by, down_by = *click_options.coords
size = native.size
left_offset = (size[:width] / 2).to_i
top_offset = (size[:height] / 2).to_i
left = -left_offset + right_by
top = -top_offset + down_by
acts.move_to(native, left, top)
else
acts.move_to(native, *click_options.coords)
end
else
acts.move_to(native)
Expand Down Expand Up @@ -469,21 +461,8 @@ def capabilities
browser.capabilities
end

def w3c?
(defined?(Selenium::WebDriver::VERSION) && (Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('4'))) ||
capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
end

def action_pause(action, duration)
if w3c?
if Gem::Version.new(Selenium::WebDriver::VERSION) >= Gem::Version.new('4.2')
action.pause(device: action.pointer_inputs.first, duration: duration)
else
action.pause(action.pointer_inputs.first, duration)
end
else
action.pause(duration)
end
action.pause(device: action.pointer_inputs.first, duration: duration)
end

def normalize_keys(keys)
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/selenium/nodes/chrome_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def send_keys(*args)
private

def perform_legacy_drag(element, drop_modifiers)
return super if chromedriver_fixed_actions_key_state? || !w3c? || element.obscured?
return super if chromedriver_fixed_actions_key_state? || element.obscured?

raise ArgumentError, 'Modifier keys are not supported while dragging in this version of Chrome.' unless drop_modifiers.empty?

Expand Down Expand Up @@ -119,7 +119,7 @@ def chromedriver_version

def native_displayed?
(driver.options[:native_displayed] != false) &&
(w3c? && chromedriver_supports_displayed_endpoint?) &&
chromedriver_supports_displayed_endpoint? &&
(!ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS'])
end
end
26 changes: 0 additions & 26 deletions lib/capybara/selenium/patches/action_pauser.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/sauce_spec_chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Capybara.register_driver :sauce_chrome do |app|
options = {
selenium_version: '4.0.0',
selenium_version: '4.8.0',
platform: 'macOS 10.12',
browser_name: 'chrome',
version: '65.0',
Expand Down
1 change: 0 additions & 1 deletion spec/selenium_spec_firefox_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ module TestSessions
when /Capybara::Session selenium_firefox_remote node #shadow_root should get visible text/
pending "Selenium doesn't currently support getting visible text for shadow root elements"
when /Capybara::Session selenium_firefox_remote node #shadow_root/
skip 'Not supported with this Selenium version' if selenium_lt?('4.1', @session)
skip 'Not supported with this geckodriver version' if geckodriver_lt?('0.31.0', @session)
when /Capybara::Session selenium node #set should submit single text input forms if ended with \\n/
pending 'Firefox/geckodriver doesn\'t submit with values ending in \n'
Expand Down

0 comments on commit 0be79d6

Please sign in to comment.