https://github.com/openatx/uiautomator2
uiautomator2 是一个可以使用Python对Android设备进行UI自动化的库
安装
- 装uiautomator2
pip install --upgrade uiautomator2
pip install pillow - 部署守护进程
python -m uiautomator2 init - 装weditor UI查看器
pip install -U weditor
运行python -m weditor - 备注:每次启动时运行python -m uiautomator2 init 和 python -m weditor就可以了
连接到设备
- 通过wifi连
要求设备IP和pc在同一网络中
import uiautomator2 as u2
d = u2.connect(‘设备ip’)
print(d.info) - 通过usb连
import uiautomator2 as u2
d = u2.connect(‘设备序列号’)
print(d.info) - u2.connect()不带参数调用,uiautomator2将从环境变量中获取设备ip(ANDROID_DEVICE_IP),如果此环境变量为空,则uiautomator将退回到connect_usb,需要保证只有一台设备连接到电脑
命令行
其中$device_ip代表设备

本文档详细介绍了UIAutomator2的安装、设备连接、命令行操作、全局设置、应用管理等核心功能,包括通过WiFi或USB连接设备、安装与管理应用、执行shell命令、进行会话管理等自动化测试所需的操作。此外,还提供了获取设备信息和执行关键事件(如屏幕开关、按键模拟)的方法。

5105

被折叠的 条评论
为什么被折叠?



