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,需要保证只有一台设备连接到电脑
命令行
其中$devi