一、adb相關命令。
1. 關閉adb服務:adb kill-server
2. 開啟adb服務:adb start-server
3. 查看當前連接的手機設備:adb devices
4. 多設設備操作,< -s 虛擬設備名稱 >
5. 重啟設備 adb reboot --指定虛擬設備 adb -s 設備名稱 reboot
6. 查看日志 adb logcat 清除日志 adb logcat -c
7. 進入linux shell下 adb shell 其中常用的linux命令 cd cat 等等 輸入su可以獲取超級管理員名稱了 要確定是否有哪些命令 進入 system/bin目錄 就知道了
8. adb connect [ip:post] #代理鏈接
9. adb shell cat
/
sys
/
class
/
net
/
wlan0
/
address #獲取MAC地址
10. adb install <name.apk> #安裝應用
11. adb uninstall <name.apk> #卸載安裝包
12. adb install
-
r <name.apk> #保存緩存文件重新安裝apk
13.adb disconnect <設備名> #斷開連接
14. adb push filename /sdcard/ #文件復制到移動設備 ,后面跟設備目錄
15. adb shell input tap #模擬位置點擊(x,y)
16. adb shell input swipe #模擬滑動( x,yx1,y1 ),還可傳入滑動緩沖
17. uiautomator dump dump: creates an XML dump of current UI hierarchy #獲取當前頁面的UI層次,保存為xml文件
二、adb模擬按鍵
keycode | 含義 |
---|---|
3 | HOME 鍵 |
4 | 返回鍵 |
5 | 打開撥號應用 |
6 | 掛斷電話 |
24 | 增加音量 |
25 | 降低音量 |
26 | 電源鍵 |
27 | 拍照(需要在相機應用里) |
64 | 打開瀏覽器 |
82 | 菜單鍵 |
85 | 播放/暫停 |
86 | 停止播放 |
87 | 播放下一首 |
88 | 播放上一首 |
122 | 移動光標到行首或列表頂部 |
123 | 移動光標到行末或列表底部 |
126 | 恢復播放 |
127 | 暫停播放 |
164 | 靜音 |
176 | 打開系統設置 |
187 | 切換應用 |
207 | 打開聯系人 |
208 | 打開日歷 |
209 | 打開音樂 |
210 | 打開計算器 |
220 | 降低屏幕亮度 |
221 | 提高屏幕亮度 |
223 | 系統休眠 |
224 | 點亮屏幕 |
231 | 打開語音助手 |
276 | 如果沒有 wakelock 則讓系統休眠 |
命令: adb shell input keyevent <keycode>
示例,點擊電源鍵:
adb shell input keyevent 26 #執行效果相當於按電源鍵。
實現原理
Hierarchy Viewer:獲得當前手機實時的UI信息,方便用於手機的自動化測試;
python中的subprocess.Popen() 或 Python os模塊:調用系統命令;
uiautomator工具:獲取界面控件信息;
adb命令:對手機進行操作;