ha4t.drivers package

Submodules

Module contents

drivers 工厂模块。

用法:

from ha4t.drivers import DRIVERS driver = DRIVERS["android"]() serial = driver.connect("emulator-5554")

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

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

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

基类:BaseDriver

connect(serial: str | None = None, port: int = 8100, **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。

push_file(local_path: str, remote_path: str, app_name: str = '') None[源代码]

remote_path 是 app 容器内相对路径,例如 Documents/xxx

pull_file(remote_path: str, local_path: str, app_name: str = '') None[源代码]

通过 t3 fsync pull 拉取 app 容器内文件。

delete_file(remote_path: str, app_name: str = '') None[源代码]

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

mkdir(remote_path: str, app_name: str = '') None[源代码]
class HarmonyDriver[源代码]

基类: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'>[源代码]

hmdriver2 截图保存为临时文件,再读取为 PIL.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。