环境搭建:python2.7+uiautomator+Android+windows 64 + PIL

背景:前几天,搭建Android端自动化UI测试环境,识别结果图片,记录问题。

项目使用框架:

 https://github.com/xiaocong/uiautomator (作者博客:http://xiaocong.github.io/

机器:windows 64位

主要遇到问题:

1. 项目使用Python 2.7,本机已安装Python 3.5,pycharm安装插件,显示pip版本不对

2. Python 2.7 安装image,依赖于Django,安装过程报IOError

3. windows 64 Python 2.7安装image,依赖安装Pillow,报错pip-build-sl1urw\pillow failed with error code 1,给出提示链接

4. python命令行中执行uiautomator中基本命令,d.info 或 d(text="Settings").click(),无响应

5. Run the jsonrcp server on Android device   gradlew cC过程卡在  > Building 96% > :app:connectedDebugAndroidTest

 

问题一:项目使用Python 2.7,本机已安装Python 3.5,pycharm安装插件,显示pip版本不对

pycharm使用本机默认python版本,修改本机环境变量Path,指定Python 2.7的安装地址;

直接使用命令行安装 ,安装成功后pycharm对应python配置下就能看到对应已安装package(package与Python interpreter对应)。

py -2 -m pip install uiautimator

 

 问题二:Python 2.7 安装image,依赖于Django,安装过程报IOError

网搜,Django包也存在和python版本的兼容问题,默认安装的2.0不适用于Python 2.7,安装时需要指定版本号,具体可查阅 https://pypi.python.org/pypi/Django/2.0 

 

执行命令

py -2 -m pip install Django==1.11.6

 

问题三:windows 64 Python 2.7安装image,依赖安装Pillow,报错pip-build-sl1urw\pillow failed with error code 1,给出提示链接

具体报错如下:

链接中提示:

不确认是否有安装PIL,尝试删除PIL

py -2 -m pip uninstall PIL   #显示未安装PIL

了解项目使用,同事明确,需要的是PIL,image非必须,转而安装PIL

PIL官网(http://www.pythonware.com/products/pil/)下载python 2.7对应exe,执行,报错无Python 2.7,命令行执行python,版本已区别出python 2.7  [感谢:http://blog.csdn.net/boycycyzero/article/details/42647161]

验证Pillow的使用,至此图像识别基础环境都安装成功。

问题四:python命令行中执行uiautomator中基本命令,d.info 或 d(text="Settings").click(),无响应,raise IOError("RPC server not started!")

运行项目文件,手机未响应,直接使用uiautomator命令,d.info后长时间无响应,杀进程后无任何信息,需要持续等待,出现了错误信息raise IOError("RPC server not started!")

git上有对应FAQ(有错误信息后搜索到,还是要等待,不要无反应就急着杀进程):

 

问题五:5. Run the jsonrcp server on Android device   gradlew cC过程卡在  > Building 96% > :app:connectedDebugAndroidTest

下载https://github.com/xiaocong/android-uiautomator-server#build 源码后,解压进入目录,执行

在第三步卡住

网上已有issue:https://github.com/xiaocong/android-uiautomator-server/issues/11

解决办法:https://github.com/xiaocong/android-uiautomator-server/wiki/Force-Start-Json-Server

Note that gradlew cC will get stuck at 96% or so but the server has started. Go and try it in python, everything should be working.

虽然卡着,它其实已经起来了

直接执行第四步和uiautomator命令

adb forward tcp:9008 tcp:9008

python

>>> from uiautomator import device as d
>>> d.info

输出结果

 

完美~

posted @ 2017-12-06 19:56  QA小虾  阅读(1661)  评论(0编辑  收藏  举报