Android自动化测试uiautomator2使用

发布于 更新于

技术文章

uiautomator2是uiautomator的升级版本,增加了对AccessibilityService服务的支持,当然在appium1.7版本以上进行支持,本篇文章介绍一下它的使用。安装安装方式很简单:pip install uiau...

uiautomator2是uiautomator的升级版本,增加了对AccessibilityService服务的支持,当然在appium1.7版本以上进行支持,本篇文章介绍一下它的使用。


安装


安装方式很简单:


pip install uiautomator2


进行初始化:


python -m uiautomator2 init


通过网上的说明,在进行初始化操作时,需要将安卓设备连接电脑,它会在设备中安装一个ATX应用(之前叫uiautomator2),并且还会装uiautomator-server(主要发送接收事件操作)、atx-agent(该服务就是在ATX应用中,好像可以不用数据线,直接可以wifi连接设备)、openstf/minicap、openstf/minitouch(可以进行快速截图的库)。


使用方式如下:


import uiautomator2 as u2


d=u2.connect('你的设备标识') #如果设备和PC电脑在同一局域网的话,还可以是你的设备IP地址。


print(https://d.info)


元素定位


使用元素定位可以使用weditor,当然也可以使用uiautomatorviewer进行定位.


安装:


pip install --pre --upgrade weditor


运行:


python3 -m weditor


继续阅读