Skip to content

Commit

Permalink
[rb] add default values to make actions easier
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed May 25, 2022
1 parent 133cbec commit cec03e1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions rb/lib/selenium/webdriver/common/action_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def tick(*action_devices)
#

def add_input(device)
device = Interactions.send(device) if device.is_a?(Symbol) && Interactions.respond_to?(device)

raise TypeError, "#{device.inspect} is not a valid InputDevice" unless device.is_a?(Interactions::InputDevice)

unless @async
Expand Down
12 changes: 12 additions & 0 deletions rb/lib/selenium/webdriver/common/interactions/interactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def pointer(kind = :mouse, name: nil)
PointerInput.new(kind, name: name)
end

def mouse(name: nil)
pointer(name: name)
end

def pen(name: nil)
pointer(:pen, name: name)
end

def touch(name: nil)
pointer(:touch, name: name)
end

def none(name = nil)
NoneInput.new(name)
end
Expand Down
16 changes: 8 additions & 8 deletions rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def default_move_duration
# @return [ActionBuilder] A self reference.
#

def pointer_down(button, device: nil, **opts)
def pointer_down(button = :left, device: nil, **opts)
button_action(button, :create_pointer_down, device: device, **opts)
end

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

def pointer_up(button, device: nil, **opts)
def pointer_up(button = :left, device: nil, **opts)
button_action(button, :create_pointer_up, device: device, **opts)
end

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

def move_to(element, right_by = nil, down_by = nil, device: nil, **opts)
def move_to(element, right_by = nil, down_by = nil, device: nil, duration: default_move_duration, **opts)
pointer = pointer_input(device)
if right_by || down_by
size = element.size
Expand All @@ -108,7 +108,7 @@ def move_to(element, right_by = nil, down_by = nil, device: nil, **opts)
left = 0
top = 0
end
pointer.create_pointer_move(duration: default_move_duration,
pointer.create_pointer_move(duration: duration,
x: left,
y: top,
origin: element,
Expand All @@ -134,9 +134,9 @@ def move_to(element, right_by = nil, down_by = nil, device: nil, **opts)
# @raise [MoveTargetOutOfBoundsError] if the provided offset is outside the document's boundaries.
#

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

def move_to_location(x, y, device: nil)
def move_to_location(x, y, device: nil, duration: default_move_duration)
pointer = pointer_input(device)
pointer.create_pointer_move(duration: default_move_duration,
pointer.create_pointer_move(duration: duration,
x: Integer(x),
y: Integer(y),
origin: Interactions::PointerMove::VIEWPORT)
Expand Down
12 changes: 11 additions & 1 deletion rb/lib/selenium/webdriver/common/interactions/pointer_press.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ module Interactions
class PointerPress < Interaction
include PointerEventProperties

BUTTONS = {left: 0, middle: 1, right: 2}.freeze
BUTTONS = {left: 0,
touch: 0,
pen_contact: 0,
middle: 1,
right: 2,
pen_barrel: 2,
x1: 3,
back: 3,
x2: 4,
forward: 4,
erase: 5}.freeze
DIRECTIONS = {down: :pointerDown, up: :pointerUp}.freeze

def initialize(source, direction, button, **opts)
Expand Down

0 comments on commit cec03e1

Please sign in to comment.