1.ADB
即Android Debug Bridge,它是 Android 開(kāi)發(fā)/測(cè)試人員不可替代的強(qiáng)大工具,也是 Android 設(shè)備玩家的好玩具。
注:有部分命令的支持情況可能與 Android 系統(tǒng)版本及定制 ROM 的實(shí)現(xiàn)有關(guān)。
2.Monkey
就是SDK中附帶的一個(gè)工具。Monkey是Android中的一個(gè)命令行工具,可以運(yùn)行在模擬器里或?qū)嶋H設(shè)備中。它向系統(tǒng)發(fā)送偽隨機(jī)的用戶事件流(如按鍵輸入、觸摸屏輸入、手勢(shì)輸入等),實(shí)現(xiàn)對(duì)正在開(kāi)發(fā)的應(yīng)用程序進(jìn)行壓力測(cè)試。Monkey測(cè)試是一種為了測(cè)試軟件的穩(wěn)定性、健壯性的快速有效的方法。
adb常用命令:
** 查看設(shè)備連接?
adb devices
**列出手機(jī)已安裝的包名
adb shell pm list packages? ? ?手機(jī)裝的app所有包名
adb shell pm list packages -s? ? 系統(tǒng)所有包名
adb shell pm list packages -3? ? 列出除了系統(tǒng)應(yīng)用的第三方應(yīng)用包名
** 查詢包
? adb shell pm list package |findstr baidu
? 或adb shell下,pm list package |grep baidu
** 清除應(yīng)用數(shù)據(jù)
?pm clear com.baidu.input
** 安裝卸載
adb install d:\com.baidu.input
adb uninstall com.baidu.input
**沉浸狀態(tài)欄
adb shell settings put global policy_control immersive.status=*
**全屏沉浸
adb shell settings put global policy_control immersive.full=*
**恢復(fù)到正常模式
adb shell settings put global policy_control null
** 查看monkey進(jìn)程
windows: adb shell ps |findstr monkey
? linux: $adb shell
? ? ? ? ? ?$ps | grep monkey
** 殺掉進(jìn)程
? adb shell kill [pid進(jìn)程號(hào)]
**-p 指定包.可指定一個(gè)包或幾個(gè)包
? adb shell monkey -p com.baidu.input -p com.sohu.input 1000
** 日志 -v
-v -v -v? ?增加-v增加日志的詳情級(jí)別
?adb shell monkey -p com.baidu.input?-v -v -v 1000
** -s (seed)偽隨機(jī)數(shù)生成器的種子值,相同的種子值運(yùn)行monkey,事件的序列相同
? adb shell monkey -p com.baidu.input?-s 1234? 重現(xiàn)種子值為1234的事件序列
**-throttle 事件間隔.事件間隔300ms
? adb shell monkey -p com.baidu.input --throttle 300 -v -v 1000
**-pct 動(dòng)作事件Monkey的事件種類一般是11種,不同的Android SDK中的Event percentages種類和順序也不同哦。
? --pct-touch 70? ? ? ?觸摸事件百分比70
? --pct-motion 5? ? ? ?手勢(shì)事件百分比70
? --pct-trackball 5? ? ?軌跡球事件百分比10
??--pct-pinchzoom 2? 縮放事件百分比2
? ?--pct-rotation 0? ? ? 屏幕旋轉(zhuǎn)事件百分比0
? ?--pct-nav 0? ? ? ? ? ? ?基本導(dǎo)航事件百分比0
? ?--pct-majornav 5? ? ?主要導(dǎo)航事件百分比5
? ?--pct-syskeys 5? ? ? ??系統(tǒng)事件百分比 5
? ?--pct-appswitch 2? ? ?Activity啟動(dòng)事件百分比2
? ?--pct-flip? 2? ? ? ? ? ? ?鍵盤(pán)翻轉(zhuǎn)事件百分比
? ?--pct-anyevent 2? ? ? ? 其他事件百分比
**-ignore 忽略錯(cuò)誤事件
? ? --ignore-crashes 忽略crash
? ? --ignore-timeouts 忽略timeouts
? ? --ignore-security-exceptions 忽略權(quán)限錯(cuò)誤
? ? --ignore-native-crashes 忽略本地應(yīng)用程序發(fā)生崩潰
**?-kill-process-after-error 錯(cuò)誤后停止應(yīng)用
**?-monitor-native-crashes? Android系統(tǒng)原生代碼中的監(jiān)視和報(bào)告崩潰
**2>&1? 錯(cuò)誤重定向 每個(gè)進(jìn)程都和三個(gè)系統(tǒng)文件相關(guān)聯(lián).標(biāo)準(zhǔn)輸入stdin,標(biāo)準(zhǔn)輸出stdout,標(biāo)準(zhǔn)錯(cuò)誤stderr.文件描述符分別為0,1,2
? ? 所以這里的2>&1,代表把標(biāo)準(zhǔn)錯(cuò)誤也輸出到標(biāo)準(zhǔn)輸出中.這樣標(biāo)準(zhǔn)輸出的日志內(nèi)容就包含了標(biāo)準(zhǔn)錯(cuò)誤的日志內(nèi)容
? 1? ./test.sh > 111.log? 標(biāo)準(zhǔn)錯(cuò)誤輸出到前臺(tái),標(biāo)準(zhǔn)輸出輸出到111.log.log日志不包含報(bào)錯(cuò)內(nèi)容
? 2 ./test.sh >? 222.log 2>&1 標(biāo)準(zhǔn)錯(cuò)誤和標(biāo)準(zhǔn)輸出都輸出到222.log日志中
? 3? ./test.sh > info.log 2>err.log? ?標(biāo)準(zhǔn)輸出輸出到info.log 標(biāo)準(zhǔn)錯(cuò)誤重定向到err.log
** 保存日志
? adb shell monkey -p com.baidu.input -v -v -v 1000 >d:\monkey.txt 2>&1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
6? 壓測(cè)命令
****cmd下****
日志保存到pc,跑monkey過(guò)程中需一直連接數(shù)據(jù)線到電腦:
adb shell monkey -p com.baidu.input --ignore-crashes--ignore-timeouts? -ignore-security-exceptions?--pct-touch 70--pct-motion 25 --pct-majornav 5 -v -v -v?--throttle 300 100000 >d:\monkey1.txt
?monkey -p 包名 忽略crash,忽略timeout,忽略權(quán)限異常,觸摸事件70,手勢(shì)事件25,主要導(dǎo)航事件5,日志三級(jí),間隔300ms,100000次事件,輸出到d盤(pán)monkey.txt.標(biāo)準(zhǔn)錯(cuò)誤也輸出到標(biāo)準(zhǔn)輸出中.
** 導(dǎo)出手機(jī)日志
adb logcat -v threadtime?>d:/loacat1.txt
** cpu 內(nèi)存監(jiān)控命令
adb shell top -d 1 |findstr com.baidu.input > d:/cpu1.txt
** 停止進(jìn)程命令
adb shell am force-stop com.baidu.xxx
****adb shell下
日志保存到手機(jī),斷開(kāi)數(shù)據(jù)線也可正常進(jìn)行,最后把日志從手機(jī)導(dǎo)出到pc進(jìn)行查看.
abd shell
$cd /sdcard
$mkdir monkeytest
$cd monkeytest
monkey命令:
monkey -p com.baidu.input --ignore-crashes--ignore-timeouts? -ignore-security-exceptions?--pct-touch 70--pct-motion 25 --pct-majornav 5 -v -v -v?--throttle 300 100000 >monkey1.txt
導(dǎo)出日志
adb pull /sdcard/monkeytest/monkey1.txt? d:/
**日志處理: