App壓力測試整理

壓力測試結果
CRASH:崩潰,應用程序在使用過程當中,非正常退出
ANR:Application Not Respondingandroid


MonkeyRunner APIs
MonkeyRunner:用來鏈接設備或模擬器
MonkeyDevice:提供安裝、卸載應用,發送模擬事件
MonkeyImage :完成圖像保存,及對比的操做shell

Monkey:在adb shell中,生成用戶或系統的僞隨機事件
MonkeyRunner:經過API定義特定命令和事件控制設備app

MonkeyRunner提供了一系列的API
能夠完成模擬事件及截圖操做
MonkeyScript
是一組能夠被Monkey識別的命令集合
能夠完成重複固定的操做ide

1.爲何要進行壓力測試?
App不穩定
提升產品的留存率測試

2.何時開展壓力測試
首輪功能測試經過後
下班後的夜間進行ui

如何實現自動化測試:
模擬各類事件流spa

adb:Android Debug Bridge
adb與手機裏的monkey進行通信
adb調試應用的入口命令行

adb shell monkey 1000
activityResuming(com.android.documentsui)
表示app從前臺調入後臺...又從後臺恢復到前臺的過程調試

獲取App包名
adb logcat|findstr START (cmp後面的是app的包名)code

給指定包打壓力
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)

相關文章
相關標籤/搜索