mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Fix Selenium non-HTML5 drag and drop test for necessary scrolling
This commit is contained in:
parent
77f764c055
commit
dffdfcfd1c
2 changed files with 16 additions and 12 deletions
|
@ -126,7 +126,10 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
end
|
||||
|
||||
def drag_to(element)
|
||||
scroll_if_needed { browser_action.drag_and_drop(native, element.native).perform }
|
||||
# Due to W3C spec compliance - The Actions API no longer scrolls to elements when necessary
|
||||
# which means Seleniums `drag_and_drop` is now broken - do it manually
|
||||
scroll_if_needed { browser_action.click_and_hold(native).perform }
|
||||
element.scroll_if_needed { browser_action.move_to(element.native).release.perform }
|
||||
end
|
||||
|
||||
def tag_name
|
||||
|
@ -191,6 +194,15 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
'/' + result.reverse.join('/')
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def scroll_if_needed
|
||||
yield
|
||||
rescue ::Selenium::WebDriver::Error::MoveTargetOutOfBoundsError
|
||||
scroll_to_center
|
||||
yield
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def boolean_attr(val)
|
||||
|
@ -221,13 +233,6 @@ private
|
|||
end
|
||||
end
|
||||
|
||||
def scroll_if_needed
|
||||
yield
|
||||
rescue ::Selenium::WebDriver::Error::MoveTargetOutOfBoundsError
|
||||
scroll_to_center
|
||||
yield
|
||||
end
|
||||
|
||||
def scroll_to_center
|
||||
script = <<-'JS'
|
||||
try {
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
<div id="drop">
|
||||
<p>It should be dropped here.</p>
|
||||
</div>
|
||||
|
||||
<div id="drop_scroll">
|
||||
<p>It should be dropped here.</p>
|
||||
</div>
|
||||
<div id="drop_html5_scroll" class="drop">
|
||||
<p>It should be dropped here.</p>
|
||||
</div>
|
||||
|
@ -142,9 +144,6 @@
|
|||
<div id="drag_scroll">
|
||||
<p>This is a draggable element.</p>
|
||||
</div>
|
||||
<div id="drop_scroll">
|
||||
<p>It should be dropped here.</p>
|
||||
</div>
|
||||
<div id="drag_html5_scroll" draggable="true">
|
||||
<p>This is an HTML5 draggable element.</p>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue