monkey常用命令解析

简介:

1、monkey程序由android系统自带,使用Java语言写成,在Android文件系统中的存放路径是:/system/framework/monkey.jar

2、Monkey.jar程序是由一个名为“monkey”的Shell脚本来启动执行,shell脚本在Android文件系统中的存放路径是:/system/bin/monkey

3、Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕、滑动Trackball、按键等操作来对设备上的程序进行测试,检测程序多久的时间会发生异常。

monkey命令格式:

adb shell monkey [options] <event-count>
adb shell monkey 800

monkey操作事件:

1.触摸事件          --ptc touch 触摸事件百分比
2.手势事件          --ptc motion 动作事件百分比
3.二指缩放事件      --ptc trackball 轨迹球事件百分比
4.轨迹事件          --ptc nav 基本导航事件百分比
5.屏幕旋转事件      --ptc majornav 主要导航事件百分比
6.基本导航事件      --ptc syskeys 系统按键事件百分比
7.主要导航事件      --ptc appswitch 应用启动事件百分比
8.系统按键事件      --ptc anyevent keypress
9.启动Activty事件  --ptc anyevent 不常用的button
10.键盘事件        --ptc anyevent 其他未涉及的事件
11.其他类型事件  

monkey参数:

常规类参数
事件类参数
约束类参数
调试类参数

常规类参数:

帮助类参数  
monkey -h  adb -s 127.0.0.1:62025 shell monkey -v 100
monkey -v -v -v 越多越详细 一般一个两个  adb shell monkey -v 100

事件类参数:

1.执行指定脚本    
adb shell monkey -f /mnt/sdcard/test1    
    
2.伪随机数生成种子值  默认:Monkey: seed=1558988255085 count=100  1558988255085不固定,count事件数100
adb shell monkey -s 8888 100  8888是种子值  
    
3.设置间隔    
adb shell monkey --throttle 3000 100  3=--throttle

设置事件百分比:

调整触摸事件百分比  
adb shell monkey -v --pct-touch 100 200  100%
adb shell monkey -v --pct-touch 30 --pct-motion 40 200  30%touch  40% motion
  
调整启动事件的百分比  
adb shell monkey -v --pct-appswitch 40 200  
  
调整屏幕旋转事件的百分比  
adb shell monkey -v --pct-rotation 60 200  
  
adb shell monkey -f  测试脚本名运行
adb shell monkey -s  随机运行

约束类参数:

adb shell monkey -p com.wyjr.jinrong 200  wyjr  
adb shell monkey -v -p com.wyjr.jinrong -p com.tencent.mm  200    wyjr and wechat
    
限制在一个或多个类别里    
adb shell monkey -c Intent.CATEGORY_LAUNCHER 100  进行Intent.CATEGORY_LAUNCHER的Activity发送100个随机事件  

调试类参数:

1.应用程序崩溃后继续发送事件  adb shell monkey --ignore-crashes  
2.超时错误继续发送事件  adb shell monkey --ignore-timeouts  
3.应用程序权限错误发送事件  adb shell monkey --ignore-exceptions  
4.其他...蛮多  adb shell monkey --dbg-no-events

综合案例:

adb shell monkey -p com.wyjr.jinrong --pct-touch 40 --pct-motion 25 --pct-appswitch 10 --pct-rotation 5 -s 1666 --throttle 400 --ignore-crashes --ignore-timeouts -v -v 400

自定义monkey脚本:

获取元素坐标点 --开发者选项--指针位置

monkey脚本API部分简介:

LaunchActivity(pkg_name, d_name)  启动应用的Activity 参数:包名和启动的Activity

Tap(x, y, tapDuration)  模拟一次手指单机事件,参数:x,y为控件坐标, tapDurtion为点击的持续事件

UserWait(sleeptime)  休眠时间

DispatchPress(keyName)  按键,参数:keycode. RotateScreen(rotationDegree,persist):旋转屏幕,参数0表示90度;persist表示旋转后是否固定,0表示旋转后恢复,非0表示固定不变。

DispatchString(input)  输入字符串

DispatchFlip(true/false)  打开/关闭软键盘

PressAndHold(x, y , pressDuration)  模拟长按事件

Drag(xStart, yStart, xEnd, yEnd, steoCount)  拖拽事件

PinchZoom(x1Start,y1Start,x1End,y1End, x2Start,y2Start,x2End,y2End,stepCount)  模拟缩放手势

LongPress()  长按2秒

DeviceWakeUp()  唤醒屏幕

PowerLog(power_log_type, test_case_status)  模拟电池电量信息

WriteLog()  将电池信息写入sd卡

RunCmd(cmd)  运行shell命令

DispatchPointer  

DispatchTrackball  模拟发送轨迹球事件

ProfileWait  等待5秒

StartCaptureFramerate()  获取帧率

EndCaptureFramerate(input)  结束时获取帧率
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值