ha4t.drivers.android module

AndroidDriver: 基于 uiautomator2 的 Android 平台驱动。

class AndroidDriver[源代码]

基类:BaseDriver

connect(serial: str | None = None, **kwargs) str[源代码]

连接设备,返回实际使用的序列号。 :raises DeviceConnectionError: 连接失败

get_device_info() dict[源代码]

返回设备基本信息字典(productName/model/serial 等)。

screen_size() Tuple[int, int][源代码]

返回屏幕分辨率 (width, height)。

screenshot() <MagicMock name='mock.Image.Image' id='140544906063568'>[源代码]

截图并返回 PIL.Image.Image 对象。

tap(x: int, y: int, duration: float = 0.1) None[源代码]

单击坐标点,duration 为按压时长(秒)。

swipe(x1: int, y1: int, x2: int, y2: int, duration: float | None = None, steps: int | None = None) None[源代码]

从 (x1,y1) 滑动到 (x2,y2)。

press(key: str) None[源代码]

模拟系统按键,如 home / back / menu。

find(**kwargs)[源代码]

根据 u2/wda/hmdriver2 属性定位元素,返回平台原生元素对象。 上层通过此方法拿到元素后自行调用 .click() / .exists 等。

find_xpath(xpath: str)[源代码]

通过 xpath 定位元素,返回平台原生元素对象。

get_element_center(**kwargs)[源代码]
app_start(app_name: str, activity: str | None = None) None[源代码]

启动应用。

app_stop(app_name: str) None[源代码]

停止应用。

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[源代码]

删除设备上的文件(默认不支持,子类按需覆写)。

property adb_device