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

feat: support w3c actions and velocity swipe #160

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 52 additions & 0 deletions wda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from wda.usbmux import fetch
from wda.usbmux.pyusbmux import list_devices, select_device
from wda.utils import inject_call, limit_call_depth, AttrDict, convert
from wda.w3c_actions import W3CActions, TouchActions


try:
Expand Down Expand Up @@ -888,6 +889,57 @@ def swipe(self, x1, y1, x2, y2, duration=0):

data = dict(fromX=x1, fromY=y1, toX=x2, toY=y2, duration=duration)
return self._session_http.post('/wda/dragfromtoforduration', data=data)

def swipe_with_velocity(self, x1: Union[int, float], y1: Union[int, float], x2: Union[int, float], y2: Union[int, float],
press_duration: float, hold_duration: float, velocity: float):
"""
Press down and drag with velocity, appium forked version of wda only
Copy link
Member

Choose a reason for hiding this comment

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

最好注明一下appium wda开始支持的版本


Args:
- x1, y1, x2, y2 (Union[int, float]): The start and end coordinates if all value is of `int` type, otherwise the start
and end percentage of screen axis
- press_duration (float): the duration before swiping (seconds)
- hold_duration (float): the duration after swiping (seconds)
- velocity (float): the velocity of swiping (pixels per second)

[[FBRoute POST:@"/wda/pressAndDragWithVelocity"] respondWithTarget:self action:@selector(handlePressAndDragCoordinateWithVelocity:)]
"""
if any(isinstance(v, float) for v in [x1, y1, x2, y2]):
size = self.window_size()
x1, y1 = self._percent2pos(x1, y1, size)
x2, y2 = self._percent2pos(x2, y2, size)

data = dict(fromX=x1, fromY=y1, toX=x2, toY=y2, pressDuration=press_duration, velocity=velocity, holdDuration=hold_duration)
return self._session_http.post('/wda/pressAndDragWithVelocity', data=data)

def perform_w3c_touch_actions(self, actions: W3CActions):
"""
Perform a sequence of w3c actions, appium forked version of wda only

For wda versions previous to v7.0.0, use `perform_touch_actions`

Args:
- actions (W3CActions): The W3C actions sequence

[[FBRoute POST:@"/actions"] respondWithTarget:self action:@selector(handlePerformW3CTouchActions:)]
"""
data = dict(actions=actions.data)
return self._session_http.post('/actions', data=data)

def perform_touch_actions(self, actions: TouchActions):
"""
Perform a sequence of touch actions, appium forked version of wda only

Removed in wda version v7.0.0, for versions after that, use `perform_w3c_touch_actions`

Args:
- actions (TouchActions): The actions sequence

[[FBRoute POST:@"/wda/touch/perform"] respondWithTarget:self action:@selector(handlePerformAppiumTouchActions:)]
[[FBRoute POST:@"/wda/touch/multi/perform"]
"""
data = dict(actions=actions.data)
return self._session_http.post('/wda/touch/multi/perform', data=data)

def _fast_swipe(self, x1, y1, x2, y2, velocity: int = 500):
"""
Expand Down
Loading