Sitelet https://github.com/appium/python-client/pull/744/files
Skip to content
Merged
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
42 changes: 18 additions & 24 deletions appium/webdriver/extensions/action_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration:
"""Scrolls from one element to another

Args:
origin_el: the element from which to being scrolling
destination_el: the element to scroll to
duration: a duration after pressing originalEl and move the element to destinationEl.
origin_el: the element from which to begin scrolling (center of element)
destination_el: the element to scroll to (center of element)
duration: defines speed of scroll action when moving from originalEl to destinationEl.
Default is 600 ms for W3C spec.

Usage:
Expand All @@ -42,32 +42,23 @@ def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration:
Returns:
Union['WebDriver', 'ActionHelpers']: Self instance
"""

# XCUITest x W3C spec has no duration by default in server side
if duration is None:
duration = 600

# w3c action requires seconds
duration_sec = duration / 1000
touch_input = PointerInput(interaction.POINTER_TOUCH, "touch")

actions = ActionChains(self)
actions.w3c_actions = ActionBuilder(self, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
dest_el_rect = destination_el.rect
actions.w3c_actions = ActionBuilder(self, mouse=touch_input)

# https://github.com/SeleniumHQ/selenium/blob/3c82c868d4f2a7600223a1b3817301d0b04d28e4/py/selenium/webdriver/common/actions/pointer_actions.py#L83
if duration_sec is None:
actions.w3c_actions.pointer_action.move_to(origin_el)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.move_to_location(dest_el_rect['x'], dest_el_rect['y'])
actions.w3c_actions.pointer_action.release()
actions.perform()
else:
actions.w3c_actions.pointer_action.move_to(origin_el)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.pause(duration_sec)
actions.w3c_actions.pointer_action.move_to_location(dest_el_rect['x'], dest_el_rect['y'])
actions.w3c_actions.pointer_action.release()
actions.perform()
actions.w3c_actions.pointer_action.move_to(origin_el)
actions.w3c_actions.pointer_action.pointer_down()
# setup duration for second move only, assuming duration always has atleast default value
actions.w3c_actions = ActionBuilder(self, mouse=touch_input, duration=duration)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the logic here - do we just reassign actions.w3c_actions property? what is then the point of having previous calls?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous actions are in touch_input, so this one just updates duration.
actions.w3c_actions.pointer_action._duration = duration can be the alternative of the ActionBuilder(self, mouse=touch_input, duration=duration) to append actions in touch_input with the duration.

>>> touch_input
<selenium.webdriver.common.actions.pointer_input.PointerInput object at 0x108c750f0>
>>> touch_input.actions
[{'type': 'pointerDown', 'duration': 0, 'button': 0}, {'type': 'pointerDown', 'duration': 0, 'button': 0}, {'type': 'pointerUp', 'duration': 0, 'button': 0}]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can also call the create_xxx methods on touch_input itself, like touch_input.create_pointer_move(), right?

actions.w3c_actions.pointer_action.move_to(destination_el)
actions.w3c_actions.pointer_action.release()
actions.perform()
return self

def drag_and_drop(self: T, origin_el: WebElement, destination_el: WebElement) -> T:
Expand Down Expand Up @@ -146,19 +137,22 @@ def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration:
start_y: y-coordinate at which to start
end_x: x-coordinate at which to stop
end_y: y-coordinate at which to stop
duration: time to take the swipe, in ms.
duration: defines the swipe speed as time taken to swipe from point a to point b, in ms.

Usage:
driver.swipe(100, 100, 100, 400)

Returns:
Union['WebDriver', 'ActionHelpers']: Self instance
"""
touch_input = PointerInput(interaction.POINTER_TOUCH, "touch")

actions = ActionChains(self)
actions.w3c_actions = ActionBuilder(self, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
actions.w3c_actions = ActionBuilder(self, mouse=touch_input)
actions.w3c_actions.pointer_action.move_to_location(start_x, start_y)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.pause(duration / 1000)
if duration > 0:
actions.w3c_actions = ActionBuilder(self, mouse=touch_input, duration=duration)
actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
actions.w3c_actions.pointer_action.release()
actions.perform()
Expand Down