-
Notifications
You must be signed in to change notification settings - Fork 276
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
Linloir
wants to merge
7
commits into
openatx:master
Choose a base branch
from
Linloir:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c279195
feat: support w3c actions and velocity swipe
Linloir 399113f
feat: add documentations
Linloir 6c633cb
feat: add suport to /wda/touch/multi/perform endpoint to support wda …
Linloir 6ef346c
feat: add documentations
Linloir bb51d7d
fix: not passing data into post request
Linloir 2e4bc63
fix: pause causing swipe to behave unexpected
Linloir 12d1ea9
feat: add swipe support for TouchMovement
Linloir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# coding: utf-8 | ||
|
||
from typing import Any, Dict, List, Optional, Union | ||
|
||
|
||
class FingerMovement: | ||
def __init__(self): | ||
self.__data: Dict[str, Any] = { | ||
"type": "pointerMove" | ||
} | ||
|
||
@property | ||
def data(self) -> Dict[str, Any]: | ||
return self.__data | ||
|
||
def with_xy(self, x: Union[int, float], y: Union[int, float]) -> "FingerMovement": | ||
self.__data["x"] = x | ||
self.__data["y"] = y | ||
return self | ||
|
||
def with_origin(self, element_uid: Optional[str]=None) -> "FingerMovement": | ||
if element_uid is not None: | ||
self.__data["origin"] = element_uid | ||
return self | ||
|
||
def with_duration(self, second: Optional[float]=None) -> "FingerMovement": | ||
if second is not None: | ||
self.__data["duration"] = second * 1000 | ||
return self | ||
|
||
|
||
class FingerAction: | ||
def __init__(self): | ||
self.__data: List[Dict[str, Any]] = [] | ||
|
||
@property | ||
def data(self) -> List[Dict[str, Any]]: | ||
return self.__data | ||
|
||
def move(self, movement: FingerMovement) -> "FingerAction": | ||
self.__data.append(movement.data) | ||
return self | ||
|
||
def down(self) -> "FingerAction": | ||
self.__data.append({"type": "pointerDown"}) | ||
return self | ||
|
||
def up(self) -> "FingerAction": | ||
self.__data.append({"type": "pointerUp"}) | ||
return self | ||
|
||
def pause(self, second: float=0.5) -> "FingerAction": | ||
self.__data.append({"type": "pause", "duration": second * 1000}) | ||
return self | ||
|
||
|
||
class W3CActions: | ||
def __init__(self): | ||
self.__data: List[Dict[str, Any]] = [] | ||
|
||
@property | ||
def data(self) -> List[Dict[str, Any]]: | ||
return self.__data | ||
|
||
def send_keys(self, text: str) -> "W3CActions": | ||
keyboard: Dict[str, Any] = { | ||
"type": "key", | ||
"id": f"keyboard{len(self.__data)}", | ||
"actions": [ | ||
(a for a in [ | ||
{"type": "keyDown", "value": v}, | ||
{"type": "keyUp", "value": v} | ||
]) for v in text | ||
] | ||
} | ||
self.__data.append(keyboard) | ||
return self | ||
|
||
def inject_touch_actions(self, *actions: FingerAction) -> "W3CActions": | ||
for action in actions: | ||
pointer: Dict[str, Any] = { | ||
"type": "pointer", | ||
"id": f"finger{len(self.__data)}", | ||
"parameters": { | ||
"pointerType": "touch" | ||
}, | ||
"actions": action.data | ||
} | ||
self.__data.append(pointer) | ||
return self | ||
|
||
def tap(self, x: Union[int, float], y: Union[int, float], element_uid: Optional[str]=None) -> "W3CActions": | ||
movement = FingerMovement().with_xy(x, y).with_origin(element_uid) | ||
action = FingerAction().move(movement).down().pause(0.1).up() | ||
Linloir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.inject_touch_actions(action) | ||
return self | ||
|
||
def press(self, x: Union[int, float], y: Union[int, float], | ||
element_uid: Optional[str]=None, second: float=2.0) -> "W3CActions": | ||
movement = FingerMovement().with_xy(x, y).with_origin(element_uid) | ||
action = FingerAction().move(movement).down().pause(second).up() | ||
self.inject_touch_actions(action) | ||
return self | ||
|
||
def swipe(self, from_x: Union[int, float], from_y: Union[int, float], | ||
to_x: Union[int, float], to_y: Union[int, float], element_uid: Optional[str]=None, | ||
press_seconds: float=0.25, swipe_seconds: Optional[float]=None, hold_seconds: float=0.25) -> "W3CActions": | ||
movement_from = FingerMovement().with_xy(from_x, from_y).with_origin(element_uid) | ||
movement_to = FingerMovement().with_xy(to_x, to_y).with_origin(element_uid).with_duration(swipe_seconds) | ||
action = FingerAction().move(movement_from).down().pause(press_seconds).move(movement_to).pause(hold_seconds).up() | ||
self.inject_touch_actions(action) | ||
return self |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好注明一下appium wda开始支持的版本