作者:虛壞叔叔
博客:https://xuhss.com
早餐店不會開到晚上,想吃的人早就來了!
https://www.python.org/downloads/windows/
我是win64位電腦 下載這個:
創建文件夾u2_project
安裝uiautomator2
pip install uiautomator2 -i https://pypi.douban.com/simple/
安裝完成後,可以看到安裝了這麼多庫
首先確保手機設備成功接通:
接下來進行最重要的操作,對移動設備初始化。
這個過程會在移動設備上,安裝一個agent
python -m uiautomator2 init
如果你的電腦上有其他的python,你想要安裝到指定的python下,可以這樣修改上面的命令
C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe -m uiautomator2 init
如果提示
ModuleNotFoundError: No module named 'dataclasses'
就安裝這個庫
pip install dataclasses
再次運行就可以看到安裝成功了:
C:\Users\Administrator\Desktop\u2_project>C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe -m uiautomator2 init
[I 220730 16:18:46 init:156] uiautomator2 version: 2.16.18
[I 220730 16:18:46 init:373] Install minicap, minitouch
[D 220730 16:18:46 init:62] Download https://tool.appetizer.io/openatx/stf-binaries/raw/0.3.0/node_modules/@devicefarmer/minitouch-prebuilt/prebuilt/x86/bin/minitouch
minitouch |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 33.6 KB/33.6 KB
?[?25h[D 220730 16:18:46 init:238] Push to /data/local/tmp/minitouch:0755
[I 220730 16:18:46 init:377] abi:x86 not supported well, skip install minicap
[D 220730 16:18:46 init:256] apk-debug package-info: None
[D 220730 16:18:46 init:257] apk-debug-test package-info: None
[I 220730 16:18:46 init:388] Install com.github.uiautomator, com.github.uiautomator.test 2.3.3
[D 220730 16:18:46 init:167] Shell: ('pm', 'uninstall', 'com.github.uiautomator')
[D 220730 16:18:47 init:167] Shell: ('pm', 'uninstall', 'com.github.uiautomator.test')
[D 220730 16:18:47 init:62] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.3.3/app-uiautomator.apk
app-uiautomator.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 2.1 MB/2.1 MB
?[?25h[D 220730 16:18:48 init:238] Push to /data/local/tmp/app-uiautomator.apk:0644
[D 220730 16:18:48 init:167] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator.apk')
[I 220730 16:18:49 init:331] - app-uiautomator.apk installed
[D 220730 16:18:49 init:62] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.3.3/app-uiautomator-test.apk
app-uiautomator-test.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 1.0 MB/1.0 MB
?[?25h[D 220730 16:18:49 init:238] Push to /data/local/tmp/app-uiautomator-test.apk:0644
[D 220730 16:18:49 init:167] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator-test.apk')
[I 220730 16:18:50 init:331] - app-uiautomator-test.apk installed
[D 220730 16:18:50 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[I 220730 16:18:50 init:346] Install atx-agent 0.10.0
[D 220730 16:18:50 init:62] Download https://tool.appetizer.io/openatx/atx-agent/releases/download/0.10.0/atx-agent_0.10.0_linux_386.tar.gz
atx-agent_0.10.0_linux_386.tar.gz |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 4.2 MB/4.2 MB
?[?25h[D 220730 16:18:51 init:238] Push to /data/local/tmp/atx-agent:0755
[D 220730 16:18:53 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[I 220730 16:18:53 init:350] Check atx-agent version
[D 220730 16:18:53 init:359] Forward: local:tcp:52537 -> remote:tcp:7912
[D 220730 16:18:54 init:359] Forward: local:tcp:52537 -> remote:tcp:7912
[D 220730 16:18:54 init:362] atx-agent version 0.10.0
[D 220730 16:18:54 init:366] device wlan ip: 172.17.99.15
Successfully init AdbDevice(serial=127.0.0.1:62001)
並且,在你的手機上,也會有一個ATX
所以剛才我們輸入的uiautomator init
命令會執行哪些操作呢 ?
他會安裝3個包,
初始化完成後,既可以在這個目錄下看到這幾個包了:
C:\Users\Administrator\.uiautomator2\cache
import uiautomator2 as u2
# 通過手機的序列號接通
d = u2.connect_usb("127.0.0.1:62001")
print(d.info)
可以看到設備的數據被正常打印出來
C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe C:/Users/Administrator/Desktop/u2_project/testu2.py
[W 220730 16:56:46 __init__:218] [pid:15028] atx-agent has something wrong, auto recovering
[D 220730 16:56:46 __init__:317] [pid:15028] [127.0.0.1:62001] device 127.0.0.1:62001 is online
[I 220730 16:56:46 init:156] uiautomator2 version: 2.16.18
[D 220730 16:56:46 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[D 220730 16:56:46 init:296] Real version: [0, 10, 0], Expect version: [0, 10, 0]
[D 220730 16:56:46 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[I 220730 16:56:46 init:350] Check atx-agent version
[D 220730 16:56:46 init:359] Forward: local:tcp:54071 -> remote:tcp:7912
[D 220730 16:56:46 init:359] Forward: local:tcp:54071 -> remote:tcp:7912
[D 220730 16:56:47 init:362] atx-agent version 0.10.0
[D 220730 16:56:47 init:366] device wlan ip: 172.17.99.15
[D 220730 16:56:47 __init__:656] [pid:15028] [127.0.0.1:62001] kill process(ps): uiautomator
[D 220730 16:56:48 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 40.0s
[D 220730 16:56:49 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 39.0s
[D 220730 16:56:50 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 38.0s
[D 220730 16:56:51 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 37.0s
[D 220730 16:56:52 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 36.0s
[D 220730 16:56:53 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 35.0s
[D 220730 16:56:54 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 33.9s
[D 220730 16:56:55 __init__:691] [pid:15028] [127.0.0.1:62001] show float window
[D 220730 16:56:56 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 32.3s
[I 220730 16:56:56 __init__:638] [pid:15028] [127.0.0.1:62001] uiautomator back to normal
{'currentPackageName': 'com.android.settings', 'displayHeight': 1920, 'displayRotation': 0, 'displaySizeDpX': 540, 'displaySizeDpY': 960, 'displayWidth': 1080, 'productName': 'SM-N960F', 'screenOn': True, 'sdkInt': 22, 'naturalOrientation': True}
點贊
收藏
轉發
一波哦,博主也支持為鐵粉絲制作專屬動態壁紙哦~python3調用百度翻譯接口
C++讀取python腳本中的dictionary字典變量以及它的鍵值對
Qt中的套件提示no complier set in kit和no debugger,出現黃色感歎號問題解決(MSVC2017)
Python+selenium 自動化 - 實現自動導入、上傳外部文件(不彈出windows窗口)
關注下面卡片即刻獲取更多編程知識,包括各種語言學習資料,上千套PPT模板和各種游戲源碼素材等等資料。更多內容可自行查看哦!