Python uiautomator 总共有三部分
1.Python uiautomator安装(开发环境安装)。
2.Android 侧 uiautomator 守护进程部分编译。
3.Python uiautomator架构说明。
一、PC 端python 部分代码可以在如下网址下载:
https://github.com/xiaocong/uiautomator
这个是xiaocong对其进行的python封装,也是这个小测试用例使用的,在这里要感谢他的辛勤劳动。
准备工作:
1.python27,不能使用python26,
我机器上是: Python 2.7.3
2.安装urllib3与uiautomator,(我用的是ubuntu,可以直接用apt-get 装pip 再用pip安装所需要的包)
3.安装android SDK,配置好adb的环境变量,这些应该都是作为android测试人员最基本的环境配置。
具体可以参考以下文章与链接
Android 开发环境安装(Eclipse+Adt+Android Sdk)
Python uiautomator的安装:
安装uiautomator:
方式一、直接安装uiautomator模块
Ubuntu环境 :
直接用pip命令安装
sudo pip install uiautomator
用python pip模块命令安装
sudo python -m install uiautomator
Windows环境:
pip install uiautomator
或者
python -m pip install uiautomator
方式二、编译安装uiautomator模块
Windows 和 Ubuntu 下面都一样:
先安装好git工具
Ubuntu 环境:
sudo apt-get install git
Windows 环境:请参考github网站安装git
然后用命令行,下载代码:
git clone https://github.com/xiaocong/uiautomator
cd uiautomator
Windows环境下:
python setup.py build
python setup.py install
如果在ubuntu 环境下:
cd uiautomator
python setup.py build
sudo python setup.py install
检查包是否安装好(ubuntu 与 Windows 一样)
jackywei@Hello-Kitty:~$ python
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import uiautomator
>>>
如果没有报错,就说明模块安装成功
简单的使用实例。
这个模块只是Android uiautomator 测试框架的一个python封装,依赖Android 4.1及以上版本。
测试代码如下:
from uiautomator import device as d
d.screen.on()
d(text="Clock").click()
如果你连接到了手机的话,此时手机应该会进入Clock应用。