Skip to content

Commit cec03e1

Browse files
committed
[rb] add default values to make actions easier
1 parent 133cbec commit cec03e1

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ def tick(*action_devices)
275275
#
276276

277277
def add_input(device)
278+
device = Interactions.send(device) if device.is_a?(Symbol) && Interactions.respond_to?(device)
279+
278280
raise TypeError, "#{device.inspect} is not a valid InputDevice" unless device.is_a?(Interactions::InputDevice)
279281

280282
unless @async

rb/lib/selenium/webdriver/common/interactions/interactions.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ def pointer(kind = :mouse, name: nil)
3838
PointerInput.new(kind, name: name)
3939
end
4040

41+
def mouse(name: nil)
42+
pointer(name: name)
43+
end
44+
45+
def pen(name: nil)
46+
pointer(:pen, name: name)
47+
end
48+
49+
def touch(name: nil)
50+
pointer(:touch, name: name)
51+
end
52+
4153
def none(name = nil)
4254
NoneInput.new(name)
4355
end

rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def default_move_duration
4646
# @return [ActionBuilder] A self reference.
4747
#
4848

49-
def pointer_down(button, device: nil, **opts)
49+
def pointer_down(button = :left, device: nil, **opts)
5050
button_action(button, :create_pointer_down, device: device, **opts)
5151
end
5252

@@ -63,7 +63,7 @@ def pointer_down(button, device: nil, **opts)
6363
# @return [ActionBuilder] A self reference.
6464
#
6565

66-
def pointer_up(button, device: nil, **opts)
66+
def pointer_up(button = :left, device: nil, **opts)
6767
button_action(button, :create_pointer_up, device: device, **opts)
6868
end
6969

@@ -96,7 +96,7 @@ def pointer_up(button, device: nil, **opts)
9696
# @return [ActionBuilder] A self reference.
9797
#
9898

99-
def move_to(element, right_by = nil, down_by = nil, device: nil, **opts)
99+
def move_to(element, right_by = nil, down_by = nil, device: nil, duration: default_move_duration, **opts)
100100
pointer = pointer_input(device)
101101
if right_by || down_by
102102
size = element.size
@@ -108,7 +108,7 @@ def move_to(element, right_by = nil, down_by = nil, device: nil, **opts)
108108
left = 0
109109
top = 0
110110
end
111-
pointer.create_pointer_move(duration: default_move_duration,
111+
pointer.create_pointer_move(duration: duration,
112112
x: left,
113113
y: top,
114114
origin: element,
@@ -134,9 +134,9 @@ def move_to(element, right_by = nil, down_by = nil, device: nil, **opts)
134134
# @raise [MoveTargetOutOfBoundsError] if the provided offset is outside the document's boundaries.
135135
#
136136

137-
def move_by(right_by, down_by, device: nil)
137+
def move_by(right_by, down_by, device: nil, duration: default_move_duration)
138138
pointer = pointer_input(device)
139-
pointer.create_pointer_move(duration: default_move_duration,
139+
pointer.create_pointer_move(duration: duration,
140140
x: Integer(right_by),
141141
y: Integer(down_by),
142142
origin: Interactions::PointerMove::POINTER)
@@ -161,9 +161,9 @@ def move_by(right_by, down_by, device: nil)
161161
# @raise [MoveTargetOutOfBoundsError] if the provided x or y value is outside the document's boundaries.
162162
#
163163

164-
def move_to_location(x, y, device: nil)
164+
def move_to_location(x, y, device: nil, duration: default_move_duration)
165165
pointer = pointer_input(device)
166-
pointer.create_pointer_move(duration: default_move_duration,
166+
pointer.create_pointer_move(duration: duration,
167167
x: Integer(x),
168168
y: Integer(y),
169169
origin: Interactions::PointerMove::VIEWPORT)

rb/lib/selenium/webdriver/common/interactions/pointer_press.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ module Interactions
2929
class PointerPress < Interaction
3030
include PointerEventProperties
3131

32-
BUTTONS = {left: 0, middle: 1, right: 2}.freeze
32+
BUTTONS = {left: 0,
33+
touch: 0,
34+
pen_contact: 0,
35+
middle: 1,
36+
right: 2,
37+
pen_barrel: 2,
38+
x1: 3,
39+
back: 3,
40+
x2: 4,
41+
forward: 4,
42+
erase: 5}.freeze
3343
DIRECTIONS = {down: :pointerDown, up: :pointerUp}.freeze
3444

3545
def initialize(source, direction, button, **opts)

0 commit comments

Comments
 (0)