Skip to content

Commit 9e2788f

Browse files
authored
Add delay to dragging to support libraries that require the mouse be held before dragging (#257)
1 parent c1c2e42 commit 9e2788f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/capybara/cuprite/browser.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,25 @@ def source
139139
raise NotImplementedError
140140
end
141141

142-
def drag(node, other, steps)
142+
def drag(node, other, steps, delay = nil)
143143
x1, y1 = node.find_position
144144
x2, y2 = other.find_position
145145

146146
mouse.move(x: x1, y: y1)
147147
mouse.down
148+
sleep delay if delay
148149
mouse.move(x: x2, y: y2, steps: steps)
149150
mouse.up
150151
end
151152

152-
def drag_by(node, x, y, steps)
153+
def drag_by(node, x, y, steps, delay = nil)
153154
x1, y1 = node.find_position
154155
x2 = x1 + x
155156
y2 = y1 + y
156157

157158
mouse.move(x: x1, y: y1)
158159
mouse.down
160+
sleep delay if delay
159161
mouse.move(x: x2, y: y2, steps: steps)
160162
mouse.up
161163
end

lib/capybara/cuprite/node.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ def hover
162162
def drag_to(other, **options)
163163
options[:steps] ||= 1
164164

165-
command(:drag, other.node, options[:steps])
165+
command(:drag, other.node, options[:steps], options[:delay])
166166
end
167167

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

171-
command(:drag_by, x, y, options[:steps])
171+
command(:drag_by, x, y, options[:steps], options[:delay])
172172
end
173173

174174
def trigger(event)

0 commit comments

Comments
 (0)