文章目錄
一、前言
二、模擬器連接端口匯總
三、ADB常用命令
1 連接命令
2 查看設備連接情況
3 把電腦上的文件或文件夾傳到模擬器里面
4 把模擬器里面的文件或文件夾傳到電腦上
5 安裝APK
6 卸載APK
7 獲取模擬器所有包名
8 獲取模擬器所有包名並且包括APK路徑
9 獲取包名對應的APK路徑
10 清理應用數據
11 啟動應用
12 關閉應用
13 模擬輸入
14 模擬按鍵
15 模擬鼠標點擊
16 模擬鼠標滑動
17 截屏
18 獲得端口號
一、前言
如果執行自動化測試,在沒有真機的情況下,我們可以選擇模擬器。目前市面上有很多模擬器,他們使用adb
連接時都會有不同的默認端口,當adb
無法自動連接模擬器時,手動使用ip+端口
連接。
二、模擬器連接端口匯總
模擬器 | adb連接代碼 | 模擬器官網 |
---|---|---|
網易Mumu | adb connect 127.0.0.1:7555 | http://mumu.163.com/ |
夜神 | adb connect 127.0.0.1:62001 | https://www.yeshen.com/ |
逍遙 | adb connect 127.0.0.1:21503 | https://www.xyaz.cn/ |
騰訊手游助手 | adb connect 127.0.0.1:5555 | https://syzs.qq.com/sempage/mrzh/index.html |
天天 | adb connect 127.0.0.1:6555 | http://www.ttmnq.com/ |
海馬玩 | adb connect 127.0.0.1:26744 | http://www.haimawan.com/ |
藍疊 (BlueStacks) | adb connect 127.0.0.1:5555 | https://www.bluestacks.cn/ |
雷電 | adb connect 127.0.0.1:5555 | http://www.ldmnq.com/ldy/baidu.html |
Genymotion | adb connect 127.0.0.1:5555 | https://www.genymotion.com/ |
iTools | adb connect 127.0.0.1:54001 | http://www.itools.cn/ |
三、ADB常用命令
1 連接命令
adb.exe connect 127.0.0.1:21503
1
2 查看設備連接情況
adb.exe devices
adb kill-server
adb start-server
adb remount
1234
3 把電腦上的文件或文件夾傳到模擬器里面
adb push D:/1.avi /mnt/avi/
1
4 把模擬器里面的文件或文件夾傳到電腦上
adb pull /mnt/avi/sex.avi D:/avi/
1
5 安裝APK
adb install d:\\qq.apk
1
6 卸載APK
adb uninstall 包名
1
比如卸載QQ:
adb uninstall com.tencent.mobileqq
1
7 獲取模擬器所有包名
adb shell pm list packages
1
8 獲取模擬器所有包名並且包括APK路徑
adb shell pm list packages -f
1
9 獲取包名對應的APK路徑
adb shell pm path packageName
1
10 清理應用數據
adb shell pm clear packageName
1
11 啟動應用
adb shell am start -n 包名/Activity類名
1
例:啟動應用寶:
adb shell am start -n com.tencent.android.qqdownloader/com.tencent.assistant.activity.SplashActivity
1
指定模擬器啟動動應用寶:
adb -s 127.0.0.1:5555 shell am start -n com.tencent.android.qqdownloader/com.tencent.assistant.activity.SplashActivity
1
12 關閉應用
adb shell am force-stop 包名
1
13 模擬輸入
adb shell input text 字符串(不支持中文)
1
14 模擬按鍵
adb shell input keyevent 鍵值
1
15 模擬鼠標點擊
adb shell input tap X Y
1
16 模擬鼠標滑動
adb shell input swipe X1 Y1 X2 Y2
1
17 截屏
adb shell screencap -p /sdcard/screencap.png
1
18 獲得端口號
這個命令不是adb
的命令,但是也很常用
netstat |findstr 127.0.0.1