From cab891ec1780cb3f6a3d9b87cdb56e1522c196dc Mon Sep 17 00:00:00 2001 From: Matt Swanson Date: Fri, 7 Jan 2022 23:40:06 -0500 Subject: [PATCH] Support option for dragging --- lib/capybara/cuprite/browser.rb | 8 ++++---- lib/capybara/cuprite/node.rb | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/capybara/cuprite/browser.rb b/lib/capybara/cuprite/browser.rb index eae6dac7..62354c58 100644 --- a/lib/capybara/cuprite/browser.rb +++ b/lib/capybara/cuprite/browser.rb @@ -112,24 +112,24 @@ def source raise NotImplementedError end - def drag(node, other) + def drag(node, other, steps) x1, y1 = node.find_position x2, y2 = other.find_position mouse.move(x: x1, y: y1) mouse.down - mouse.move(x: x2, y: y2) + mouse.move(x: x2, y: y2, steps: steps) mouse.up end - def drag_by(node, x, y) + def drag_by(node, x, y, steps) x1, y1 = node.find_position x2 = x1 + x y2 = y1 + y mouse.move(x: x1, y: y1) mouse.down - mouse.move(x: x2, y: y2) + mouse.move(x: x2, y: y2, steps: steps) mouse.up end diff --git a/lib/capybara/cuprite/node.rb b/lib/capybara/cuprite/node.rb index ad88fadc..3efab57c 100644 --- a/lib/capybara/cuprite/node.rb +++ b/lib/capybara/cuprite/node.rb @@ -159,12 +159,16 @@ def hover command(:hover) end - def drag_to(other) - command(:drag, other.node) + def drag_to(other, **options) + options[:steps] ||= 1 + + command(:drag, other.node, options[:steps]) end - def drag_by(x, y) - command(:drag_by, x, y) + def drag_by(x, y, **options) + options[:steps] ||= 1 + + command(:drag_by, x, y, options[:steps]) end def trigger(event)