我是靠谱客的博主 单纯月光,最近开发中收集的这篇文章主要介绍uiautomator2任意操作Android自动化测试,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

简介

uiautomator2 是一个Android UI自动化框架,支持Python编写测试脚本对设备进行自动化。底层基于Google uiautomator,Google提供的uiautomator库可以获取屏幕上任意一个APP的任意一个控件属性,并对其进行任意操作,但有两个缺点:1. 测试脚本只能使用Java语言 2. 测试脚本必须每次被上传到设备上运行。 我们希望测试能够用一个更脚本化的语言,例如Python编写,同时可以每次所见即所得地修改测试、运行测试。原理是在手机上运行了一个http服务器,将uiautomator中的功能开放出来,然后再将这些http接口,封装成Python库。 uiautomator2项目是对xiaocong/uiautomator的增强,主要有以下部分:

  • 设备和开发机可以脱离数据线,通过WiFi互联(基于atx-agent)
  • 集成了openstf/minicap达到实时屏幕投频,以及实时截图
  • 集成了openstf/minitouch达到精确实时控制设备
  • 修复了xiaocong/uiautomator经常性退出的问题
  • 代码进行了重构和精简,方便维护
    Requirements: Android OS Version >= 4.4 Python >=2.7 || <= 3.6

安装

下载安装uiautomator2

# Since uiautomator2 is still under development, you have to add --pre to install the development version
pip install --upgrade --pre uiautomator2

# Or you can install directly from github source
git clone https://github.com/openatx/uiautomator2
pip install -e uiautomator2

如果处理截屏,就安装pillow

pip install pillow

一般遇到问题,更新到最新版本就可以了:

pip install --upgrade --pre uiautomator2

初始化

部署相关守护进程到设备,电脑连接上一个手机或多个手机, 确保adb已经添加到环境变量中,执行下面的命令会自动安装本库所需要的设备端程序:uiautomator-server 、atx-agent、openstf/minicap、openstf/minitouch
有时候init也会出错,请参考手动Init指南

# init 所有的已经连接到电脑的设备
python -m uiautomator2 init

安装weditor(UI Inspector)

因为uiautomator是独占资源,所以当atx运行的时候uiautomatorviewer是不能用的,为了减少atx频繁的启停,我们开发了基于浏览器技术的weditor UI查看器。

pip install --pre -U weditor

连接到设备

import uiautomator2 as u2

d = u2.connect('10.0.0.1') # alias for u2.connect_wifi('10.0.0.1')
print(d.info)

参考

https://github.com/openatx/uiautomator2

最后

以上就是单纯月光为你收集整理的uiautomator2任意操作Android自动化测试的全部内容,希望文章能够帮你解决uiautomator2任意操作Android自动化测试所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部