Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py] Allow overriding the default 250 msecs duration of pointer movement #9336

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions py/selenium/webdriver/common/action_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ class ActionChains(object):
another.
"""

def __init__(self, driver):
def __init__(self, driver, duration=250):
"""
Creates a new ActionChains.

:Args:
- driver: The WebDriver instance which performs user actions.
- duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in PointerInput
"""
self._driver = driver
self._actions = []
self.w3c_actions = ActionBuilder(driver)
self.w3c_actions = ActionBuilder(driver, duration=duration)

def perform(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/common/actions/action_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@


class ActionBuilder(object):
def __init__(self, driver, mouse=None, keyboard=None):
def __init__(self, driver, mouse=None, keyboard=None, duration=250):
if not mouse:
mouse = PointerInput(interaction.POINTER_MOUSE, "mouse")
if not keyboard:
keyboard = KeyInput(interaction.KEY)
self.devices = [mouse, keyboard]
self._key_action = KeyActions(keyboard)
self._pointer_action = PointerActions(mouse)
self._pointer_action = PointerActions(mouse, duration=duration)
self.driver = driver

def get_device_with(self, name):
Expand Down
14 changes: 10 additions & 4 deletions py/selenium/webdriver/common/actions/pointer_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@

class PointerActions(Interaction):

def __init__(self, source=None):
def __init__(self, source=None, duration=250):
"""
Args:
- source: PointerInput instance
- duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in source
"""
if not source:
source = PointerInput(interaction.POINTER_MOUSE, "mouse")
self.source = source
self._duration = duration
super(PointerActions, self).__init__(source)

def pointer_down(self, button=MouseButton.LEFT):
Expand All @@ -49,15 +55,15 @@ def move_to(self, element, x=None, y=None):
else:
left = 0
top = 0
self.source.create_pointer_move(origin=element, x=int(left), y=int(top))
self.source.create_pointer_move(origin=element, duration=self._duration, x=int(left), y=int(top))
return self

def move_by(self, x, y):
self.source.create_pointer_move(origin=interaction.POINTER, x=int(x), y=int(y))
self.source.create_pointer_move(origin=interaction.POINTER, duration=self._duration, x=int(x), y=int(y))
return self

def move_to_location(self, x, y):
self.source.create_pointer_move(origin='viewport', x=int(x), y=int(y))
self.source.create_pointer_move(origin='viewport', duration=self._duration, x=int(x), y=int(y))
return self

def click(self, element=None):
Expand Down