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)
|
||||
click_options = ClickOptions.new(keys, options)
|
||||
return native.click if click_options.empty?
|
||||
scroll_if_needed do
|
||||
action_with_modifiers(click_options) do |action|
|
||||
click_options.coords? ? action.click : action.click(native)
|
||||
end
|
||||
end
|
||||
click_with_options(click_options)
|
||||
rescue StandardError => err
|
||||
if err.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
|
||||
err.message =~ /Other element would receive the click/
|
||||
|
@ -101,19 +97,15 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
|
||||
def right_click(keys = [], **options)
|
||||
click_options = ClickOptions.new(keys, options)
|
||||
scroll_if_needed do
|
||||
action_with_modifiers(click_options) do |action|
|
||||
click_options.coords? ? action.context_click : action.context_click(native)
|
||||
end
|
||||
click_with_options(click_options) do |action|
|
||||
click_options.coords? ? action.context_click : action.context_click(native)
|
||||
end
|
||||
end
|
||||
|
||||
def double_click(keys = [], **options)
|
||||
click_options = ClickOptions.new(keys, options)
|
||||
scroll_if_needed do
|
||||
action_with_modifiers(click_options) do |action|
|
||||
click_options.coords? ? action.double_click : action.double_click(native)
|
||||
end
|
||||
click_with_options(click_options) do |action|
|
||||
click_options.coords? ? action.double_click : action.double_click(native)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -233,6 +225,18 @@ private
|
|||
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
|
||||
script = <<-'JS'
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,7 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
|
|||
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. ' \
|
||||
'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
|
||||
raise
|
||||
end
|
||||
|
@ -62,6 +62,13 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
|
|||
|
||||
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)
|
||||
case keys
|
||||
when String
|
||||
|
|
Loading…
Reference in New Issue