Skip to content

Commit 43f47a1

Browse files
committed
feat: faster swipe
1 parent e007f5e commit 43f47a1

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
[![downloads](https://pepy.tech/badge/hmdriver2)](https://pepy.tech/project/hmdriver2)
66

77

8+
>写这个项目前github上已有个[hmdirver](https://github.com/mrx1203/hmdriver),但它是侵入式(需要提前在手机端安装一个testRunner app)。另外鸿蒙官方提供的hypium自动化框架,使用较为复杂,依赖繁杂。于是决定重写一套。
89
9-
>写这个项目前github上已有个[hmdirver](https://github.com/mrx1203/hmdriver),但它是侵入式(需要提前在手机端安装一个testRunner app)。另外鸿蒙官方提供的`hypium`自动化框架,使用较复杂,依赖繁杂。于是决定重写一套框架,解决上述两个框架的弊端。
1010

1111
`hmdriver2`是一款支持`鸿蒙Next`系统的UI自动化框架,**无侵入式**,提供应用管理,UI操作,元素定位等功能,轻量高效,上手简单,快速实现鸿蒙应用自动化测试需求。
1212

1313

1414
# Feature
15-
- 支持鸿蒙Next系统的自动化
15+
- 支持鸿蒙Next系统的UI自动化测试
1616
- **无侵入式**,无需在手机安装基于ArkTS的testRunner APP
1717
- 稳定高效,直接和鸿蒙底层uitest服务交互
1818
- 轻量,上手简单,即插即用
@@ -351,7 +351,7 @@ d.swipe(x1, y1, x2, y2, spped)
351351
d.swipe(600, 2600, 600, 1200, speed=2000) # 上滑
352352
d.swipe(0.5, 0.8, 0.5, 0.4, speed=2000)
353353
```
354-
参数`x1`, `y1`表示滑动的起始点,`x2`, `y2`表示滑动的终点,`speed`为滑动速率, 范围:200~40000, 不在范围内设为默认值为600, 单位: 像素点/秒
354+
参数`x1`, `y1`表示滑动的起始点,`x2`, `y2`表示滑动的终点,`speed`为滑动速率, 范围:200~40000, 不在范围内设为默认值为2000, 单位: 像素点/秒
355355

356356
#### 输入
357357
```python3

docs/DEVELOP.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@
132132
{"result":null}
133133
```
134134

135+
### swipe
136+
**send**
137+
```
138+
{"module":"com.ohos.devicetest.hypiumApiHelper","method":"callHypiumApi","params":{"api":"Driver.swipe","this":"Driver#0","args":[630,2176,630,1360,7344],"message_type":"hypium"},"request_id":"20240913123029322117","client":"127.0.0.1"}
139+
```
140+
**recv**
141+
```
142+
{"result":null}
143+
```
144+
135145

136146
### findComponents
137147
**send**

hmdriver2/driver.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
import json
44
import uuid
55
from typing import Type, Any, Tuple, Dict, Union, List
6-
7-
try:
8-
# Python3.8+
9-
from functools import cached_property
10-
except ImportError:
11-
from cached_property import cached_property
6+
from functools import cached_property # python3.8+
127

138
from . import logger
149
from .utils import delay
@@ -146,7 +141,7 @@ def screen_off(self):
146141
def unlock(self):
147142
self.screen_on()
148143
w, h = self.display_size
149-
self.hdc.swipe(0.5 * w, 0.8 * h, 0.5 * w, 0.2 * h, speed=600)
144+
self.swipe(0.5 * w, 0.8 * h, 0.5 * w, 0.2 * h, speed=6000)
150145

151146
@cached_property
152147
def display_size(self) -> Tuple[int, int]:
@@ -268,7 +263,7 @@ def long_click(self, x: Union[int, float], y: Union[int, float]):
268263
self._invoke(api, args=[point.x, point.y])
269264

270265
@delay
271-
def swipe(self, x1, y1, x2, y2, speed=1000):
266+
def swipe(self, x1, y1, x2, y2, speed=2000):
272267
"""
273268
Perform a swipe action on the device screen.
274269
@@ -277,12 +272,18 @@ def swipe(self, x1, y1, x2, y2, speed=1000):
277272
y1 (float): The start Y coordinate as a percentage or absolute value.
278273
x2 (float): The end X coordinate as a percentage or absolute value.
279274
y2 (float): The end Y coordinate as a percentage or absolute value.
280-
speed (int, optional): The swipe speed in pixels per second. Default is 1000. Range: 200-40000. If not within the range, set to default value of 600.
275+
speed (int, optional): The swipe speed in pixels per second. Default is 2000. Range: 200-40000. If not within the range, set to default value of 2000.
281276
"""
277+
282278
point1 = self._to_abs_pos(x1, y1)
283279
point2 = self._to_abs_pos(x2, y2)
284280

285-
self.hdc.swipe(point1.x, point1.y, point2.x, point2.y, speed=speed)
281+
if speed < 200 or speed > 40000:
282+
logger.warning("`speed` is not in the range[200-40000], Set to default value of 2000.")
283+
speed = 2000
284+
285+
api = "Driver.swipe"
286+
self._invoke(api, args=[point1.x, point1.y, point2.x, point2.y, speed])
286287

287288
@delay
288289
def input_text(self, x, y, text: str):

hmdriver2/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def delay(func):
1111
After each UI operation, it is necessary to wait for a while to ensure the stability of the UI,
1212
so as not to affect the next UI operation.
1313
"""
14-
DELAY_TIME = 0.4
14+
DELAY_TIME = 0.5
1515

1616
@wraps(func)
1717
def wrapper(*args, **kwargs):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "UI Automation Framework for Harmony Next"
55
authors = ["codematrixer <chenli_gogo@163.com>"]
66
license = "MIT"
77
readme = "README.md"
8-
include = ["*/asset/*"]
8+
include = ["*/assets/*"]
99

1010
[tool.poetry.dependencies]
1111
python = "^3.8"

0 commit comments

Comments
 (0)