当前位置:   article > 正文

安卓android自动化测试-uiautomator/uiautomator2_android uiautomator

android uiautomator

介绍

uiautomator是基于adb,可实现操控app的功能,可实现类似xpath爬虫这些通过元素id、元素内容来定位并 实现相关操作如点击等,如:

  1. from uiautomator import device as d
  2. d.screen.on()
  3. d(text="Clock").click()

根据发展历程,有如下三种开源框架,目前基本都用uiautomator2,支持usb或者wifi连接。 

建议使用 uiautomator2,uiautomator-python 已不在维护。

uiautomator-python

GitHub - xiaocong/uiautomator: Python wrapper of Android uiautomator test tool.

uiautomator2

https://github.com/openatx/uiautomator2

前言

很早以前,我用uiautomator+java实践过Android APP自动化测试,不过今天要提的不是uiautomator,而是uiautomator2。听起来uiautomator2像是uiautomator的升级版,但是这两款框架仅仅是名字上比较相似,实际上没有任何关联。

一、uiautomator/uiautomator2的前生今世

项目地址:https://github.com/openatx/uiautomator2

1.官方文档介绍

2.梳理一下脉络

先有的谷歌uiautomator,但是只支持java;
后来一个名为hexiaocong的开发者基于uiautomator封装了python版本,支持python代码运行;
而受其启发,uiautomator2作者开发了uiautomator2。所以它们的诞生顺序应该是:uiautomator(谷歌版)-->uiautomator(python版)-->uiautomator2

3.三款框架对比

框架支持语言特点
uiautomatorjava谷歌开源,仅支持Android
xiaocong/uiautomatorpython开源,仅支持Android
uiautomator2python开源,仅支持Android

二、uiautomator2简介

1.项目组成

  • uiautomator-server:主服务
  • minicap:实现实时屏幕投频,以及实时截图
  • minitouch:用于精确实时控制设备
  • atx-agent:运行在设备上的驻守程序,go开发,用于保活设备上相关的服务
  • weditor:类似于uiautomatorviewer,专门为本项目开发的辅助编辑器

2.工作原理

1)各部分职责

  • Python:编写脚本,向移动设备发起http请求;
  • 移动设备:运行了封装了uiautomator2的http服务,解析python脚本发起的请求,并转化成uiautomator2可识别的代码;

2)运行过程

  1. 移动设备上运行atx-agent守护进程,随后atx-agent启动uiautomator2服务,默认7912端口进行监听;
  2. 在PC上编写python脚本并执行(相当于发送 HTTP 请求到移动设备的 server 端);
  3. 移动设备通过 WIFI 或 USB 接收到 PC 上发来的 HTTP 请求,执行指定的操作,从而操作移动设备https://github.com/openatx/uiautomator2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/709009
推荐阅读
相关标签
  

闽ICP备14008679号