標籤:ext seed log bit 中間鍵 意思 -- 為什麼 app
壓力測試結果:
CRASH:崩潰,應用程式在使用過程中,非正常退出
ANR:Application Not Responding
MonkeyRunner APIs
MonkeyRunner:用來串連裝置或模擬器
MonkeyDevice:提供安裝、卸載應用,發送類比事件
MonkeyImage :完成映像儲存,及對比的操作
Monkey:在adb shell中,產生使用者或系統的偽隨機事件
MonkeyRunner:通過API定義特定命令和事件控制裝置
MonkeyRunner提供了一系列的API
可以完成類比事件及操作
MonkeyScript
是一組可以被Monkey識別的命令集合
可以完成重複固定的操作
1.為什麼要進行壓力測試?
App不穩定
提高產品的留存率
2.什麼時候開展壓力測試
首輪功能測試通過後
下班後的夜間進行
如何?自動化測試:
類比各種事件流
adb:Android Debug Bridge
adb與手機裡的monkey進行通訊
adb調試應用的入口
adb shell monkey 1000
activityResuming(com.android.documentsui)
表示app從前台調入後台...又從後台恢複到前台的過程
擷取App包名
adb logcat|findstr START (cmp後面的是app的包名)
給指定包打壓力
adb shell monkey -p package 1000
-v
作用:命令列上的每一個-v都將增加反饋資訊的詳細資訊層級
比較常用的是-v -v -v ,即最多詳細,一般會儲存到指定
檔案中供開發人員尋找bug原因時使用
--throttle參數
指定事件之間的間隔
adb shell monkey -p packagename --throttle 間隔毫秒 執行次數
seed參數
指定隨機產生數的seed值
如果用相同的seed值再次運行monkey,將產生相同的事件序列
adb shell monkey -s<seed><event-count>
adb shell monkey -p com.bit_health.android -s 7672 1000
觸摸事件
設定觸摸事件百分比
adb shell monkey --pct-touch <percent>
adb shell monkey -v -p com.bit_health.android --pct-touch 100 1000
可以在輸出結果中的Event percentages中查看是否是
觸摸事件百分百,0表示觸摸事件
動作事件
設定動作事件百分比
adb shell monkey --pct-motion <percent>
這裡設定的百分比要與其他事件的百分比之和等於100
adb shell monkey -v -p com.bit_health.android --pct-touch 50 --pct-motion 30 500
軌跡球事件
設定軌跡球事件百分比
adb shell monkey --pct-trackball <percent>
基本導航事件
設定基本導肮事件百分比,輸入裝置的上、下、左、右
adb shell monkey --pct-nav <percent>
主要導航事件
設定主要導航事件百分比,相容中間鍵、返回鍵、菜單按鍵
adb shell monkey --pct-majornav <percent>
系統導航事件
設定系統導航事件百分比,HOME、Back、撥號、音量鍵
adb shell monkey --pct-syskeys <percent>
啟動Activity事件
設定啟動Activity的事件百分比
adb shell monkey --pct-appswitch <percent>
不常用事件
設定不常用事件的百分比
adb shell monkey --pct-anyevent <percent>
崩潰事件
忽略崩潰和異常
adb shell monkey --ignore-crashes <event-count>
逾時事件
忽略逾時事件
adb shell monkey --ignore-timeouts <event-count>
如果發生了ANR事件,可以在手機中查看
1.輸入adb shell命令,進入到手機
2.跳轉anr目錄,cd /data/anr/
3.在anr目錄中,more traces.txt 查看報錯資訊
Monkey Script
1.DispatchTrackball命令
軌跡球事件
DispatchTrackball(long downtime,long eventide,
int action,float x,float y,float pressure,
float size,int metastate,float xprecision,
float ypercision,int device,int edgeflags)
action 0代表按下,1代表談起,x和y代表座標點
2.DispatchPointer命令
點擊事件
DispatchPointer(long downtime,long eventide,
int action,float x,float y,float pressure,
float size,int metastate,float xprecision,
float ypercision,int device,int edgeflags)
action 0代表按下,1代表談起,x和y代表座標點
3.DispatchString命令
輸入字串事件
DispatchString(String text)
4.LaunchActivity命令
啟動應用
LaunchActivity(package,Activity)
5.UserWait命令
等待事件
UserWait(1000)
6.DispatchPress命令
按下索引值
DispatchPress(int keycode)#keycode 66 斷行符號鍵
執行個體:重複點擊搜尋100次
1.啟動App
2.點擊輸入框
3.輸入查詢詞
4.點擊鍵盤的斷行符號
5.點擊搜尋按鈕
6.等待結果的出現
7.點擊clear按鈕
手機不能執行電腦上的指令碼
將指令碼push到手機中
adb push mook.script /data/local/tmp/
之後執行adb shell monkey -f mook.script 2
執行的效果是無法正確啟動app
(!!!)需要在mainfest資訊清單檔中聲明android:exported="true"
意思是允許該activity被外部調用
使用monkey script編寫指令碼最大的困難是沒有調試功能
也沒有截屏操作
MonkeyRunner
1.MonkeyRunnner API-alert
警告框
void alert(String message,String title,String okTitle)
2.MonkeyRunner Api-waitForConnection
等待裝置串連,有多個device id,需要指明具體哪個裝置
waitForConnection(float timeout,String deviceid)
3.MonkeyDevice API -drag
拖動
drag(tuple start,tuple end ,float duration,integer steps)
start 起點位置
end 終點位置
duration手勢持續的時間
steps 插值點的步數,預設10
4.MonkeyDevice API -press
按鍵
press(String keycode,dictionary type)
keycode名,Down,UP,DOWN_AND_UP
5.MonkeyDevice API -startActivity
啟動應用
startActivity(package+‘/‘+activity)
6.MonkeyDevice API - touch
點擊
touch(integer x,integer y,integer type)
x 座標值, y座標值
type:DOWN,UP,DOWN_AND_UP
7.MonkeyDevice API - type
輸入
type(String message)
8.MonkeyDevice API - takeSnapshot
截屏
MonkeyImage takeSnapshot()
9.MonkeyImage API - sameAs
映像對比
boolean sameAS(MonkeyImage other,float percent)
10.MonkeyImage API - writetoFile
儲存影像檔
void writetoFile(String path,String format)
App壓力測試整理