Monkey啟動的命令行腳本為:monkey [options] < count >
Options可以分為5類 1. 基本配置類參數(shù) 2. 事件類型和頻率參數(shù) 3. 約束限制類參數(shù) 4. 調(diào)試類參數(shù) 5.官方隱藏類參數(shù)
Monkey啟動
shell啟動
adb shell
monkey [options] <count>
monkey 啟動后會不斷的向被測對象發(fā)送隨機(jī)事件流,直到事件執(zhí)行完畢或者發(fā)生異常時(shí)才停止,停止monkey 的方法是殺死m(xù)onkey的進(jìn)程
adb shell ps | grep monkey
adb shell kill pid
Monkey測試方法
-
常規(guī)穩(wěn)定性測試
adb shell monkey -p com.xxx.xxx --pct-touch 40 --pct-motion 25 --pct-appswitch 10 --pct-rotation 5 -s 12358 --throttle 400 --ignore-crashes --ignore-timeouts -v 500000- -p 獲取測試應(yīng)用的包名
> adb shell
pm list package - --pct-xxx 限制monkey執(zhí)行的事件類型和占比
- -s 指定命令執(zhí)行的seed值
根據(jù)seed值生成對應(yīng)的事件流,同一個(gè)seed生成的事件流是完全相同的,指定seed值是為了發(fā)現(xiàn)問題時(shí)便于復(fù)現(xiàn) - --throttle參數(shù)控制monkey每個(gè)操作之間的時(shí)間間隔
- --ignore-crash --ignore-timeouts 是操作遇到意外時(shí)繼續(xù)執(zhí)行
- -v指定log的詳細(xì)級別
- -p 獲取測試應(yīng)用的包名
-
自定義腳本的穩(wěn)定性測試
讓monkey測試某個(gè)特定場景(執(zhí)行固定的事件流),用戶將monkey腳本的規(guī)范編寫好腳本,存放到手機(jī)上,啟動monkey 通過 -f scriptfile參數(shù)調(diào)用腳本即可。Monkey 腳本只能通過坐標(biāo)的方式來定位點(diǎn)擊和移動事件的屏幕位置,這里就需要提前獲取坐標(biāo)信息,最簡單的方法就是打開手機(jī)中開發(fā)人員選項(xiàng),打開“顯示指針位置”,隨后,在屏幕上的每次操作在導(dǎo)航欄上都會顯示坐標(biāo)信息
編寫好腳本后,存放到手機(jī)或模擬器的sdcard中
adb push monkey.script /sdcard/
執(zhí)行腳本
adb shell monkey -f /sdcard/monkey.script -v 1 -
結(jié)合輔助命令,獲取更多信息
獲取 logcat 日志信息
adb shell logcat -v time>log.txt獲取內(nèi)存信息
adb shell dumpsys meminfo <進(jìn)程名>獲取CPU消耗信息
adb shell top -n 1|find "進(jìn)程名"獲取電量信息
adb shell dumpsys battery獲取GPU信息
adb shell dumpsys gfxinfo <進(jìn)程名>-
獲取流量信息
adb shell cat/proc/uid_stat/<被測應(yīng)用的UID>/tcp_rcv
查看被測應(yīng)用的進(jìn)程ID(PID)
adb shell ps | grep <被測應(yīng)用包名>
查看被測應(yīng)用的用戶ID(UID)
adb shell cat /proc/$pid/status日志保存
- 保存在PC中
adb shell monkey [option] <count> >d:\monkey.txt - 保存在手機(jī)中
adb shell
monkey [option] <count> > /mnt/sdcard/monkey.txt - 標(biāo)注流與錯(cuò)誤流分開保存
monkey [option] <count> 1 >/sdcard/monkey.txt 2>/sdcard/error.txt
- 保存在PC中