ha4t.drivers.base module
BaseDriver: 所有平台驱动的抽象基类。
每个平台实现此接口,Device 层统一通过 BaseDriver 方法调用,
消灭 api.py / __init__.py 中散落的 if platform == 判断。
-
class BaseDriver[源代码]
基类:ABC
-
abstractmethod connect(serial: str | None = None, **kwargs) → str[源代码]
连接设备,返回实际使用的序列号。
:raises DeviceConnectionError: 连接失败
-
abstractmethod get_device_info() → dict[源代码]
返回设备基本信息字典(productName/model/serial 等)。
-
abstractmethod screen_size() → Tuple[int, int][源代码]
返回屏幕分辨率 (width, height)。
-
abstractmethod screenshot() → <MagicMock name='mock.Image.Image' id='140544906063568'>[源代码]
截图并返回 PIL.Image.Image 对象。
-
abstractmethod tap(x: int, y: int, duration: float = 0.1) → None[源代码]
单击坐标点,duration 为按压时长(秒)。
-
abstractmethod swipe(x1: int, y1: int, x2: int, y2: int, duration: float | None = None, steps: int | None = None) → None[源代码]
从 (x1,y1) 滑动到 (x2,y2)。
-
abstractmethod press(key: str) → None[源代码]
模拟系统按键,如 home / back / menu。
-
abstractmethod find(**kwargs)[源代码]
根据 u2/wda/hmdriver2 属性定位元素,返回平台原生元素对象。
上层通过此方法拿到元素后自行调用 .click() / .exists 等。
-
abstractmethod find_xpath(xpath: str)[源代码]
通过 xpath 定位元素,返回平台原生元素对象。
-
abstractmethod app_start(app_name: str, activity: str | None = None) → None[源代码]
启动应用。
-
abstractmethod app_stop(app_name: str) → None[源代码]
停止应用。
-
abstractmethod app_current() → str[源代码]
返回当前前台应用的包名/bundleId。
-
app_clear(app_name: str) → None[源代码]
清除应用数据(默认不支持,子类按需覆写)。
-
push_file(local_path: str, remote_path: str) → None[源代码]
上传文件到设备(默认不支持,子类按需覆写)。
-
pull_file(remote_path: str, local_path: str) → None[源代码]
从设备下载文件(默认不支持,子类按需覆写)。
-
delete_file(remote_path: str) → None[源代码]
删除设备上的文件(默认不支持,子类按需覆写)。