压力测试结果:
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)