openatx/uiautomator2的学习使用

https://github.com/openatx/uiautomator2

需求

  • Android版本 4.4+
  • Python 3.6+ (社区反馈3.8.0不支持, 但是3.8.2支持)

准备

  1. 开启了开发者选项的安卓手机
  2. 运行pip3 install -U uiautomator2 安装uiautomator2
  3. 运行python3 -m uiautomator2 init安装包含httprpc服务的apk到手机+atx-agent, minicap, minitouch (在过去的版本中,这一步是必须执行的,但是从1.3.0之后的版本,当运行python代码u2.connect()时就会自动推送这些文件了)
import uiautomator2 as u2
d = u2.connect() # connect to device
print(d.info)
如下输出,证明成功了:
{'currentPackageName': 'net.oneplus.launcher', 'displayHeight': 1920, 'displayRotation': 0, 'displaySizeDpX': 411, 'displaySizeDpY': 731, 'displayWidth': 1080, 'productName': 'OnePlus5', '
screenOn': True, 'sdkInt': 27, 'naturalOrientation': True}
  1. Install daemons to a device (Optional)
    电脑连接上一个手机或多个手机, 确保adb已经添加到环境变量中,执行下面的命令会自动安装本库所需要的设备端程序:uiautomator-serveratx-agentopenstf/minicapopenstf/minitouch
# init 所有的已经连接到电脑的设备
python -m uiautomator2 init
  1. Install weditor (可视化工具)
    因为uiautomator是独占资源,所以当atx运行的时候uiautomatorviewer是不能用的,为了减少atx频繁的启停,我们开发了基于浏览器技术的weditor UI查看器。https://github.com/openatx/weditor
    安装方法(备注: 目前最新的稳定版为 0.1.0)
pip install weditor
# 进入网页
weditor
image.png
# 连接设备
d = u2.connect()
# d = u2.connect_wifi(ip)
# 检查并维持设备端守护进程处于运行状态
d.healthcheck()
# 解锁屏幕        
d.unlock()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

办法总比困难多多

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值