Skip to content

Commit

Permalink
Add delay to dragging to support libraries that require the mouse be …
Browse files Browse the repository at this point in the history
…held before dragging
  • Loading branch information
trobrock committed Feb 9, 2024
1 parent c5ff466 commit 1061b47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/capybara/cuprite/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,25 @@ def source
raise NotImplementedError
end

def drag(node, other, steps)
def drag(node, other, steps, delay = nil)
x1, y1 = node.find_position
x2, y2 = other.find_position

mouse.move(x: x1, y: y1)
mouse.down
sleep delay if delay
mouse.move(x: x2, y: y2, steps: steps)
mouse.up
end

def drag_by(node, x, y, steps)
def drag_by(node, x, y, steps, delay = nil)
x1, y1 = node.find_position
x2 = x1 + x
y2 = y1 + y

mouse.move(x: x1, y: y1)
mouse.down
sleep delay if delay
mouse.move(x: x2, y: y2, steps: steps)
mouse.up
end
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/cuprite/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ def hover
def drag_to(other, **options)
options[:steps] ||= 1

command(:drag, other.node, options[:steps])
command(:drag, other.node, options[:steps], options[:delay])
end

def drag_by(x, y, **options)
options[:steps] ||= 1

command(:drag_by, x, y, options[:steps])
command(:drag_by, x, y, options[:steps], options[:delay])
end

def trigger(event)
Expand Down

0 comments on commit 1061b47

Please sign in to comment.