monkey自定义脚本实践
monkey专题系列:
1.monkey命令详解
2.android monkey 测试方法实践
上一篇文章monkey测试方法实践中,已经说过monkey隐藏的两个命令,–pck-blacklist-file<黑名单文件>,–pck-whitelist-file<白名单文件>,monkey还有一个隐藏的命令那就是:
–f<脚本文件>:可以指定monkey的自定义脚本
一般monkey测试都是随机的测试事件,假如我们需要测试某一个特定的场景,普通的命令很难办到,这是就是需要自定义脚本这个命令了,它的使用方式也是很简单方便的,只要我们按照monkey的脚本规范写好脚本,之后将它保存到手机中,然后运行monkey的时候使用-f 命令指定脚本就行。
- monkey自定义脚本格式:
monkey的源码MonkeySourceScript.java类中有一段关于monkey脚本规则的描述MonkeySourceScript.java有兴趣的同学可以去看一下这个源码,我们看一下源码对脚本规则的描述:/** * monkey event queue. It takes a script to produce events sample script format: * * <pre> * type= raw events * count= 10 * speed= 1.0 * start data >> * captureDispatchPointer(5109520,5109520,0,230.75429,458.1814,0.20784314,0.06666667,0,0.0,0.0,65539,0) * captureDispatchKey(5113146,5113146,0,20,0,0,0,0) * captureDispatchFlip(true) * ... * </pre> */复制代码
解释他们的意思
#声明脚本的类型 type= raw events #脚本的执行次数,由于monkey运行次数在命令设置的,这里的设置是无效的 count= 10 #事件执行时间间隔,这个也是通过命令来设置,这里不起作用 speed= 1.0 #脚本的入口,说明脚本从下面开始执行 start data >> #下全是monkey命令 captureDispatchPointer(5109520,5109520,0,230.75429,458.1814,0.20784314,0.06666667,0,0.0,0.0,65539,0) captureDispatchKey(5113146,5113146,0,20,0,0,0,0) captureDispatchFlip(true)复制代码
知道了monkey脚本书写的基本格式,在来看一眼monkey常见脚本API
1.LaunchActivity(包名,Activity名称)
启动被测应用的某个Activity
2.TAp(x,y,TapDuration)
一次单击事件
x,y:是坐标
TapDuration:持续的时间,单位毫秒
3.DispatchPress(keyName)
模拟一个按键
keyName:按键的名称
4.RotateScreen(RotationDegree,peresist)
旋转屏幕
RotationDegree:0~3分别表示顺时针的四个方向
peresist:是否存留
5.DispatchFiip(true/false)
打开或关闭软键盘
6.LongPress()长按2秒
7.PressAndHold(x,y,PressDuration)
模拟长按事件
x,y:点击的坐标
PressDuration:持续时常,单位毫秒
8.DispatchString(input)
输入字符串
input:输入的内容
9.Drag(xStart,yStart,xEnd,yEnd,pCount)
模拟拖动操作
xStart,yStart:开始的坐标值
xEnd,yEnd:结束的坐标值
pCount:滑动事件的次数
10.PinchZoom(pt1xStart,pt1yStart,pt1xEnd,pt1yEnd,pt2xStart,pt2ystart,pt2xEnd,pt2yEnd)
手势缩放事件
pt1xStart,pt1yStart:第一个手指起始的坐标位置
pt1xEnd,pt1yEnd:第一个手指结束的坐标位置
pt2xStart,pt2ystart:第二个手指开始的坐标位置
pt2xEnd,pt2yEnd:第二个手指结束的坐标位置
11.UserWait(sleepTime)
设置睡眠时间
sleepTime:等待时间,单位毫秒
12.DeviceWake()
唤醒设备屏幕 - monkey 脚本的事例
type = user
count = 1
speed = 500
start data >>
#启动应用程序
LaunchActivity(com.michael.words,com.michael.words.activity.SplashActivity)
UserWait(5000)
#点击下步按钮
Tap(615,609)
UserWait(1000)
#点击编辑框
Tap(200,85,1000)
#输入sg
DispatchString(sg)复制代码
将文件保存为monkey.script文件,之后将脚本push到手机里,然后执行命令
monkey -f /sdcard/monkey.script -v 1
效果截图
执行后打印的log信息如下:
shell@mako:/ $ monkey -f /sdcard/monkey.script -v 1
monkey -f /sdcard/monkey.script -v 1
WARNING: linker: app_process has text relocations. This is wasting memory and isa security risk. Please fix.
WARNING: linker: app_process has text relocations. This is wasting memory and isa security risk. Please fix.
:Monkey: seed=1496304348065 count=1
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
Replaying 0 events with speed 1.0
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.michael.words/.activity.Splash
Activity;end// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.michael.words/.activity.SplashActivity } in pack
age com.michael.words// Allowing start of Intent { cmp=com.michael.words/.activity.ConfigActivity} in package com.michael.words// activityResuming(com.michael.words)
:Sending Touch (ACTION_DOWN): 0:(615.0,516.0)
:Sending Touch (ACTION_UP): 0:(615.0,516.0)// Allowing start of Intent { cmp=com.michael.words/.activity.MainActivity }in package com.michael.words// activityResuming(com.michael.words)
:Sending Touch (ACTION_DOWN): 0:(200.0,85.0)
:Sending Touch (ACTION_UP): 0:(200.0,85.0)
// Shell command input text sg status was 0
Events injected: 9
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=8030ms (0ms mobile, 0ms wifi, 8030ms not connecte
d)
// Monkey finished复制代码
monkey自定义脚本实践相关推荐
- Monkey自定义脚本测试
自定义脚本的稳定性测试 常规Monkey测试执行的是随机的事件流,但如果只是想让Monkey测试某个特定场景这时候就需要用到自定义脚本了,Monkey支持执行用户自定义脚本的测试,用户只需要按照Mon ...
- monkey自定义脚本
编辑脚本 能够让monkey按照你预先写好的脚本去跑代码如下 type = raw events count = 1 speed = 1.0start data >>LaunchActiv ...
- 自定义脚本实践-------有谱* 自动播放
弹吉他是我的小爱好,但是对于我这种菜鸡,找谱子当然是很重要的一个事情. 其中用的比较多的就是 有谱么,点击进入 要是有小伙伴儿也喜欢吉他可以去试试,谱子挺全的,而且这里面有个功能就是有谱子的播放,对于 ...
- 【我的Android进阶之旅】Android自定义Lint实践
背景 2017年8月份的时候,我在公司开始推广Lint.FindBugs等静态代码检测工具.然后发现系统自带的Lint检测的Issue不满足我们团队内部的特定需求,因此去自定义了部分Lint规则.这个 ...
- 转:iFire:玩聚 SRBacks 自定义脚本及样式表
感谢iFire的第一时间修改并试用,而且调试出如此清新的样式. 下面转贴一下他的自定义脚本和样式表: 玩聚 SRBacks 自定义脚本及样式表 admin @ 2009-01-11 02:34 59 ...
- Cacti 自定义脚本监控
Cacti 自定义脚本监控 ************************************************* 脚本内容: [root@cacti scripts]# cat get_ ...
- centos7执行sh文件_一文看懂centos7如何管理自定义脚本服务
概述 centos6如果要添加自定义脚本服务只需要把脚本放到/etc/init.d然后授权后用chkconfig添加后就可以管理了,那么centos7又是怎么添加自定义脚本服务呢? CentOS7添加 ...
- [系统集成] RT(Request Tracker)执行自定义脚本及发送微信、短信的实现方法
RT(Request Tracker)是一个基于 Perl 语言的开源状态跟踪和工作流系统,支持审批.权限管理等功能,中文化支持的也不错,可以作为企业的流程审批系统使用.可惜的是,该系统在国内使用的不 ...
- 在nagios中使用nrpe自定义脚本
nrpe的安装 tar xvfz nrpe-2.13.tar.gz cd nrpe-2.13 ./configure make all make install-plugin make ins ...
最新文章
- java.sql.Connection.close() vs null
- ffmpeg结构体(二)
- 我在河南安阳拍摄的一个山村小孩儿
- 谈谈这些年前端的变化
- PID控制器开发笔记之九:基于前馈补偿的PID控制器的实现
- python 字符串替换换行,Python fstring:替换换行符/lineb
- paramiko上传下载
- 花书+吴恩达深度学习(七)优化方法之基本算法(Momentum, Nesterov, AdaGrad, RMSProp, Adam)
- set.contains()分析
- 腾讯变革 150 天全记录
- linux下esc退不出vi
- 《Thinking in Java》Ten 内部类
- 自动驾驶 2-1 第 1 课补充阅读:传感器和计算硬件 -- 下
- winserver2012安装语言包
- 关于WiFi密码破解的一些心得
- FU-A STAP-A 拆包 打包 小议
- SOPCAST所有频道的地址
- QQ号被盗了申诉回来马上又被盗了怎么办
- sodo与visodo的日常使用
- 【elementUI】el-table树形结构样式修改-gif展示说明 按要求自取即可