1.安裝 uiautomator2 模塊
pip install uiautomator2 pip install pillow
2.手機安裝uiautomator apk
python -m uiautomator2 init
兩種方法連接手機
- wifi
- 通過USB數據線將手機鏈接電腦
通過wifi連接的話,需要獲取手機連接WIFI的IP地址
3.驗證腳本
import uiautomator2 as u2 d = u2.connect('192.168.31.234') print(d.info)
返回手機信息
4.安裝weditor
pip install weditor
5.啟動 weditor
python -m weditor
weditor啟動報錯,找不到StringIO模塊
解決辦法: 修改__main__.py腳本 將“import StringIO”改下面的代碼:
try: from io import StringIO except ImportError: from cStringIO import StringIO
接着啟動 weditor 啟動時提示:No module named ‘cv2’
pip install opencv-python
繼續啟動 weditor ,會彈出頁面 http://atx.open.netease.com/ , 填上手機 的ip地址或者通過USB連接的手機設備號連接, 點擊Connect 連接手機, Reload就會顯示手機頁面
文章參考:
uiautomator2 使用Python測試 Android應用: https://www.cnblogs.com/fnng/p/8486863.html
WEditor使用方法介紹與異常解決:https://blog.csdn.net/botree_chan/article/details/81413789