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

來源:互聯網
上載者:User

標籤:預設   pychar   fail   錯誤資訊   https   uninstall   python   star   faq   

背景:搭建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的使用,至此Image Recognition基礎環境都安裝成功。

問題四: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

輸出結果

 

完美~

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.