Skip to content

Commit 7ace9f6

Browse files
authored
Merge pull request #182 from swanson/swanson/add-drag-steps
Support `steps` option for dragging
2 parents 0924f53 + cab891e commit 7ace9f6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/capybara/cuprite/browser.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,24 @@ def source
121121
raise NotImplementedError
122122
end
123123

124-
def drag(node, other)
124+
def drag(node, other, steps)
125125
x1, y1 = node.find_position
126126
x2, y2 = other.find_position
127127

128128
mouse.move(x: x1, y: y1)
129129
mouse.down
130-
mouse.move(x: x2, y: y2)
130+
mouse.move(x: x2, y: y2, steps: steps)
131131
mouse.up
132132
end
133133

134-
def drag_by(node, x, y)
134+
def drag_by(node, x, y, steps)
135135
x1, y1 = node.find_position
136136
x2 = x1 + x
137137
y2 = y1 + y
138138

139139
mouse.move(x: x1, y: y1)
140140
mouse.down
141-
mouse.move(x: x2, y: y2)
141+
mouse.move(x: x2, y: y2, steps: steps)
142142
mouse.up
143143
end
144144

lib/capybara/cuprite/node.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,16 @@ def hover
159159
command(:hover)
160160
end
161161

162-
def drag_to(other)
163-
command(:drag, other.node)
162+
def drag_to(other, **options)
163+
options[:steps] ||= 1
164+
165+
command(:drag, other.node, options[:steps])
164166
end
165167

166-
def drag_by(x, y)
167-
command(:drag_by, x, y)
168+
def drag_by(x, y, **options)
169+
options[:steps] ||= 1
170+
171+
command(:drag_by, x, y, options[:steps])
168172
end
169173

170174
def trigger(event)

0 commit comments

Comments
 (0)