Skip to content

Commit

Permalink
[rb] warn about upcoming changes to #move_to
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed May 27, 2022
1 parent 9990fba commit be70262
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Metrics/MethodLength:

Metrics/ModuleLength:
CountComments: false
Max: 101
Max: 110
Exclude:
- 'lib/selenium/webdriver/common/platform.rb'
- 'spec/**/*'
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/action_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def pause(deprecated_device = nil, deprecated_duration = nil, device: nil, durat
deprecate_method(deprecated_device, deprecated_duration)

device ||= deprecated_device || pointer_input
device.create_pause(duration || deprecated_duration)
device.create_pause(deprecated_duration || duration)
self
end

Expand Down
13 changes: 9 additions & 4 deletions rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def pointer_up(button = :left, 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
WebDriver.logger.warn("moving to an element with offset currently tries to use
the top left corner of the element as the origin; in Selenium 4.3 it will use the in-view
center point of the element as the origin.")
size = element.size
left_offset = (size[:width] / 2).to_i
top_offset = (size[:height] / 2).to_i
Expand Down Expand Up @@ -134,12 +137,13 @@ def move_to(element, right_by = nil, down_by = nil, device: nil, duration: defau
# @raise [MoveTargetOutOfBoundsError] if the provided offset is outside the document's boundaries.
#

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

def move_to_location(x, y, device: nil, duration: default_move_duration)
def move_to_location(x, y, device: nil, duration: default_move_duration, **opts)
pointer = pointer_input(device)
pointer.create_pointer_move(duration: duration,
x: Integer(x),
y: Integer(y),
origin: Interactions::PointerMove::VIEWPORT)
origin: Interactions::PointerMove::VIEWPORT,
**opts)
tick(pointer)
self
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class PointerPress < Interaction
x1: 3,
back: 3,
x2: 4,
forward: 4,
erase: 5}.freeze
forward: 4}.freeze
DIRECTIONS = {down: :pointerDown, up: :pointerUp}.freeze

def initialize(source, direction, button, **opts)
Expand Down
16 changes: 7 additions & 9 deletions rb/spec/integration/selenium/webdriver/action_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ module WebDriver
pointer_options = {pressure: 0.8, tilt_x: -40, tilt_y: -10, twist: 177}
actions = driver.action(devices: :pen)
.move_by(x_val + 5, y_val + 5)
.pointer_down(**pointer_options)
.move_by(2, 2, duration: 0.8)
.pointer_down
.move_by(2, 2, duration: 0.8, **pointer_options)
.pointer_up

start = Time.now
Expand All @@ -288,15 +288,13 @@ module WebDriver
expect(move_to).to include("button" => "-1",
"pageX" => (x_val + 5).to_s,
"pageY" => (y_val + 5).floor.to_s)
expect(down).to include("button" => "0",
"pageX" => (x_val + 5).to_s,
"pageY" => (y_val + 5).floor.to_s,
"tiltX" => "-40",
"tiltY" => "-10",
"twist" => "177")
expect(down).to include("button" => "0")
expect(move_by).to include("button" => "-1",
"pageX" => (x_val + 5 + 2).to_s,
"pageY" => (y_val + 5 + 2).floor.to_s)
"pageY" => (y_val + 5 + 2).floor.to_s,
"tiltX" => "-40",
"tiltY" => "-10",
"twist" => "177")
expect(up).to include("button" => "0",
"pageX" => (x_val + 5 + 2).to_s,
"pageY" => (y_val + 5 + 2).floor.to_s)
Expand Down

0 comments on commit be70262

Please sign in to comment.