1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Allow forcing HTML5 or legacy dragging when using Selenium driver with drag_to

This commit is contained in:
Thomas Walpole 2019-07-30 17:06:31 -07:00
parent 064785ae09
commit f2f31f6965
2 changed files with 11 additions and 5 deletions

View file

@ -396,8 +396,13 @@ module Capybara
#
# @param [Capybara::Node::Element] node The element to drag to
# @param [Hash] options Driver specific options for dragging. May not be supported by all drivers.
# @option options [Numeric] :delay (0.05) When using Chrome/Firefox with Selenium and HTML5 dragging this is the number
# of seconds between each stage of the drag.
# @option options [Boolean] :html5 When using Chrome/Firefox with Selenium enables to force the use of HTML5
# (true) or legacy (false) dragging. If not specified the driver will attempt to
# detect the correct method to use.
#
# @return [Capybara::Node::Element] The element
# @return [Capybara::Node::Element] The dragged element
def drag_to(node, **options)
synchronize { base.drag_to(node.base, **options) }
self

View file

@ -4,13 +4,14 @@ class Capybara::Selenium::Node
module Html5Drag
# Implement methods to emulate HTML5 drag and drop
def drag_to(element, delay: 0.05)
def drag_to(element, html5: nil, delay: 0.05)
driver.execute_script MOUSEDOWN_TRACKER
scroll_if_needed { browser_action.click_and_hold(native).perform }
if driver.evaluate_script(LEGACY_DRAG_CHECK, self)
perform_legacy_drag(element)
else
html5 = !driver.evaluate_script(LEGACY_DRAG_CHECK, self) if html5.nil?
if html5
perform_html5_drag(element, delay)
else
perform_legacy_drag(element)
end
end