[python3.5][uiautomator]android uiautomatro自动化测试-1
2016-11-05 16:53
246 查看
android UI自动化测试,可以使用python+uiautomator
一、 python3.5+uiautomator安装
uiautomator模块安装可直接通过python PIP安装pip install uiautomator
或者到网站下载安装
https://pypi.python.org/pypi/uiautomator
二、环境配置
根据官网文档介绍需要配置如下python环境配置 确保python可正常使用即可
jdk环境配置,确保ANDROID_HOME路径正确
ADB 环境配置,确保PC adb可用
终端unkonw sources勾选
但实际发现往往还是无法调试起来,如有必要需要安装
jdk 配置JAVA环境变量
三、uiautomator使用
3.1 模块导入from uiautomator import device from uiautomator import device as d
博客中全部以from uiautomator import device as d为例
3.2 多个终端连接
如果要同时操作多个终端,可通过终端序列号区分终端
from uiautomator import device d1=Device("序列号1") d2=Device("序列号2")
3.3 点亮屏幕/灭屏
d.screen.on() d.screen.off()
判断屏幕状态
if d.screen=="on" if d.screen=="off"
3.4 唤醒终端/睡眠
d.wakeup() d.sleep()
3.5 查看信息
d.info
执行结果
>>> d.info {'displaySizeDpY': 640, 'displayWidth': 1080, 'sdkInt': 22, 'productName': 'XXXXX', 'displayRotation': 0, 'currentPackageName': 'com.zte.mifavor.launcher', 'naturalOrientation': True, 'displayHeight': 1776, 'screenOn': True, 'displaySizeDpX': 360}
查看空间text文本是 微信 的信息
d(text="微信").info
执行结果,可以看到空间的相关信息,位置坐标等信息
>>> d(text="微信").info {'visibleBounds': {'bottom': 1776, 'top': 1573, 'left': 434, 'right': 646}, 'scrollable': False, 'enabled': True, 'clickable': True, 'contentDescription': '微信', 'checked': False, 'focused': False, 'checkable': False, 'longClickable': True, 'className': 'android.widget.TextView', 'packageName': 'com.zte.mifavor.launcher', 'text': '微信', 'focusable': True, 'childCount': 0, 'bounds': {'bottom': 1776, 'top': 1573, 'left': 434, 'right': 646}, 'resourceName': None, 'selected': False}
相关文章推荐
- 使用uiautomator的python封装进行android的UI测试
- 使用uiautomator的python封装进行android的UI测试
- 利用Robot Framework和Python wrapper of Android uiautomator的Android测试自动化
- python 自动化uiautomator 测试android报错:ioerror RPC server not started
- python+uiautomator+adb dump(Android手机自动化) 根据文本寻找所在坐标并点击
- 使用uiautomator的python封装进行android的UI测试
- python+android+uiautomator的环境搭建
- WIFI开关用例(UIAutomator+python+Android)
- Python wrapper of Android uiautomator test tool
- Android进阶--android自动化测试python+uiautomator
- 让Python程序在Android手机上跑起来
- 用python脚本实现的android代码管理工具rrdt
- 让Python在Android系统上飞一会儿
- 让Python在Android系统上飞一会儿:第三节 在电脑上编写程序在手机上运行
- set up Android development environment and python
- 使用Python开发Android应用程序:第三节 在电脑上编写程序在手机上运行
- 让python在android系统上飞一会儿:第四节 使用WebView制作程序界面
- run Python script in Android.mk on Android building system
- android sl4a的python安装记录
- 让Python在Android系统上飞一会儿:第一节 在手机上配置Python运行环境