Skip to content

Commit 4fbc8cb

Browse files
committed
[rb] make pause easier to use in action builder sequence
includes deprecating ordered parameters in #pause and #pauses in favor of keywords
1 parent 9026176 commit 4fbc8cb

3 files changed

Lines changed: 49 additions & 11 deletions

File tree

rb/lib/selenium/webdriver/common/action_builder.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ def wheel_inputs
193193
# @return [ActionBuilder] A self reference.
194194
#
195195

196-
def pause(device, duration = nil)
197-
device.create_pause(duration)
196+
def pause(deprecated_device = nil, deprecated_duration = nil, device: nil, duration: 0)
197+
deprecate_method(deprecated_device, deprecated_duration)
198+
199+
device ||= deprecated_device || pointer_input
200+
device.create_pause(duration || deprecated_duration)
198201
self
199202
end
200203

@@ -214,7 +217,14 @@ def pause(device, duration = nil)
214217
# @return [ActionBuilder] A self reference.
215218
#
216219

217-
def pauses(device, number, duration = nil)
220+
def pauses(deprecated_device = nil, deprecated_number = nil, deprecated_duration = nil,
221+
device: nil, number: nil, duration: 0)
222+
deprecate_method(deprecated_device, deprecated_duration, deprecated_number, method: :pauses)
223+
224+
number ||= deprecated_number || 2
225+
device ||= deprecated_device || pointer_input
226+
duration ||= deprecated_duration || 0
227+
218228
number.times { device.create_pause(duration) }
219229
self
220230
end
@@ -268,11 +278,20 @@ def add_input(device)
268278

269279
unless @async
270280
max_device = @devices.max { |a, b| a.actions.length <=> b.actions.length }
271-
pauses(device, max_device.actions.length) if max_device
281+
pauses(device: device, number: max_device.actions.length) if max_device
272282
end
273283
@devices << device
274284
device
275285
end
286+
287+
def deprecate_method(device = nil, duration = nil, number = nil, method: :pause)
288+
return unless device || number || duration
289+
290+
WebDriver.logger.deprecate "ActionBuilder##{method} with ordered parameters",
291+
':device, :duration, :number keywords',
292+
id: method
293+
end
294+
276295
end # ActionBuilder
277296
end # WebDriver
278297
end # Selenium

rb/spec/integration/selenium/webdriver/action_builder_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ module WebDriver
210210
x_offset = (destination_rect.x - origin_rect.x).ceil
211211
y_offset = (destination_rect.y - origin_rect.y).ceil
212212

213-
driver.action.move_to(origin, x_offset, y_offset).click.perform
214-
sleep 0.2
213+
driver.action.move_to(origin, x_offset, y_offset).pause(duration: 1).click.perform
215214
expect(destination.attribute(:value)).to eq('Clicked')
216215
end
217216
end

rb/spec/unit/selenium/webdriver/common/action_builder_spec.rb

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,47 @@ module WebDriver
188188
it 'creates pause with default duration' do
189189
allow(mouse).to receive :create_pause
190190

191-
builder.pause(mouse)
191+
builder.pause(device: mouse)
192192

193-
expect(mouse).to have_received(:create_pause).with(nil)
193+
expect(mouse).to have_received(:create_pause).with(0)
194194
end
195195

196196
it 'creates pause with provided duration' do
197197
allow(mouse).to receive :create_pause
198198

199-
builder.pause(mouse, 5)
199+
builder.pause(device: mouse, duration: 5)
200200

201201
expect(mouse).to have_received(:create_pause).with(5)
202202
end
203+
204+
it 'has deprecated ordered parameters' do
205+
expect {
206+
builder.pause(mouse, 3)
207+
}.to have_deprecated(:pause)
208+
end
203209
end
204210

205211
describe '#pauses' do
212+
it 'adds 2 pauses to a pointer device by default' do
213+
allow(mouse).to receive :create_pause
214+
215+
builder.pauses
216+
217+
expect(mouse).to have_received(:create_pause).with(0).exactly(2).times
218+
end
219+
206220
it 'adds multiple pause commands' do
207221
allow(mouse).to receive :create_pause
208222

209-
builder.pauses(mouse, 3)
223+
builder.pauses(device: mouse, number: 3)
210224

211-
expect(mouse).to have_received(:create_pause).with(nil).exactly(3).times
225+
expect(mouse).to have_received(:create_pause).with(0).exactly(3).times
226+
end
227+
228+
it 'has deprecated ordered parameters' do
229+
expect {
230+
builder.pauses(mouse, 3)
231+
}.to have_deprecated(:pauses)
212232
end
213233
end
214234

0 commit comments

Comments
 (0)