Skip to content

Commit

Permalink
Merge pull request #11 from YeungHoiChiu/feat-drag-action
Browse files Browse the repository at this point in the history
feat: add drag、motionEvent in uia
  • Loading branch information
ZhouYixun authored Jun 11, 2024
2 parents 60c8992 + 39aabf5 commit 4e3fbfc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
40 changes: 40 additions & 0 deletions client/uia_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,43 @@ def swipe(self, start_x: Union[int, float], start_y: Union[int, float], end_x: U
else:
self.logger.error("perform swipe action failed.")
raise SonicRespException(b.err.message)

def drag(self, start_x: Union[int, float], start_y: Union[int, float], end_x: Union[int, float],
end_y: Union[int, float], duration_ms: Union[int, float], element_id: str, dest_el_id: str):
self.check_session_id()
data = {
"startX": start_x,
"startY": start_y,
"endX": end_x,
"endY": end_y,
"step": int(duration_ms / 5) if duration_ms else 100,
"elementId": element_id,
"destElId": dest_el_id,
}
b = self.resp_handler.get_resp(
HttpUtil.create_post(self._remote_url + "/session/" + self.session_id + "/touch/drag").body(
json.dumps(data)))
if b.err is None:
self.logger.info("perform drag action %s.", json.dumps(data))
else:
self.logger.error("perform drag action failed.")
raise SonicRespException(b.err.message)

def touch_action(self, action: str, x: Union[int, float], y: Union[int, float]):
self.check_session_id()
if action.lower() not in ('down', 'up', 'move'):
raise ValueError("action must be `up`、`down`、`move`")
data = {
'params': {
'x': x,
'y': y
}
}
b = self.resp_handler.get_resp(
HttpUtil.create_post(
self._remote_url + "/session/" + self.session_id + f"/touch/{action}").body(json.dumps(data)))
if b.err is None:
self.logger.info(f"perform touch action {action} %s.", json.dumps(data))
else:
self.logger.error(f"perform touch action {action} failed.")
raise SonicRespException(b.err.message)
7 changes: 7 additions & 0 deletions uia2/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ def long_press(self, x: Union[int, float], y: Union[int, float], duration_ms: Un
def swipe(self, start_x: Union[int, float], start_y: Union[int, float], end_x: Union[int, float],
end_y: Union[int, float], duration_ms: Union[int, float]):
return self._client.swipe(start_x, start_y, end_x, end_y, duration_ms)

def drag(self, start_x: Union[int, float], start_y: Union[int, float], end_x: Union[int, float],
end_y: Union[int, float], duration_ms: Union[int, float], element_id: str, dest_el_id: str):
return self._client.drag(start_x, start_y, end_x, end_y, duration_ms, element_id, dest_el_id)

def touch_action(self, action: str, x: Union[int, float], y: Union[int, float]):
return self._client.touch_action(action, x, y)

0 comments on commit 4e3fbfc

Please sign in to comment.