Workaround FF/marionette issue with offset clicking near viewport edge
This commit is contained in:
parent
6261641d70
commit
fd5ef4fa03
|
@ -85,11 +85,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
def click(keys = [], **options)
|
def click(keys = [], **options)
|
||||||
click_options = ClickOptions.new(keys, options)
|
click_options = ClickOptions.new(keys, options)
|
||||||
return native.click if click_options.empty?
|
return native.click if click_options.empty?
|
||||||
scroll_if_needed do
|
click_with_options(click_options)
|
||||||
action_with_modifiers(click_options) do |action|
|
|
||||||
click_options.coords? ? action.click : action.click(native)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue StandardError => err
|
rescue StandardError => err
|
||||||
if err.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
|
if err.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
|
||||||
err.message =~ /Other element would receive the click/
|
err.message =~ /Other element would receive the click/
|
||||||
|
@ -101,21 +97,17 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
|
|
||||||
def right_click(keys = [], **options)
|
def right_click(keys = [], **options)
|
||||||
click_options = ClickOptions.new(keys, options)
|
click_options = ClickOptions.new(keys, options)
|
||||||
scroll_if_needed do
|
click_with_options(click_options) do |action|
|
||||||
action_with_modifiers(click_options) do |action|
|
|
||||||
click_options.coords? ? action.context_click : action.context_click(native)
|
click_options.coords? ? action.context_click : action.context_click(native)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def double_click(keys = [], **options)
|
def double_click(keys = [], **options)
|
||||||
click_options = ClickOptions.new(keys, options)
|
click_options = ClickOptions.new(keys, options)
|
||||||
scroll_if_needed do
|
click_with_options(click_options) do |action|
|
||||||
action_with_modifiers(click_options) do |action|
|
|
||||||
click_options.coords? ? action.double_click : action.double_click(native)
|
click_options.coords? ? action.double_click : action.double_click(native)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def send_keys(*args)
|
def send_keys(*args)
|
||||||
native.send_keys(*args)
|
native.send_keys(*args)
|
||||||
|
@ -233,6 +225,18 @@ private
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def click_with_options(click_options)
|
||||||
|
scroll_if_needed do
|
||||||
|
action_with_modifiers(click_options) do |action|
|
||||||
|
if block_given?
|
||||||
|
yield action
|
||||||
|
else
|
||||||
|
click_options.coords? ? action.click : action.click(native)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def scroll_to_center
|
def scroll_to_center
|
||||||
script = <<-'JS'
|
script = <<-'JS'
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
|
||||||
if tag_name == 'tr'
|
if tag_name == 'tr'
|
||||||
warn 'You are attempting to click a table row which has issues in geckodriver/marionette - see https://github.com/mozilla/geckodriver/issues/1228. ' \
|
warn 'You are attempting to click a table row which has issues in geckodriver/marionette - see https://github.com/mozilla/geckodriver/issues/1228. ' \
|
||||||
'Your test should probably be clicking on a table cell like a user would. Clicking the first cell in the row instead.'
|
'Your test should probably be clicking on a table cell like a user would. Clicking the first cell in the row instead.'
|
||||||
return find_css('th:first-child,td:first-child')[0].click
|
return find_css('th:first-child,td:first-child')[0].click(keys, options)
|
||||||
end
|
end
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
@ -62,6 +62,13 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def click_with_options(click_options)
|
||||||
|
# Firefox/marionette has an issue clicking with offset near viewport edge
|
||||||
|
# scroll element to middle just in case
|
||||||
|
scroll_to_center if click_options.coords?
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def _send_keys(keys, actions, down_keys = nil)
|
def _send_keys(keys, actions, down_keys = nil)
|
||||||
case keys
|
case keys
|
||||||
when String
|
when String
|
||||||
|
|
Loading…
Reference in New Issue