Monkey基础

Moneykey 参数

adb shell monkey , 指随机时间数量,运行结果:
adb shell monkey 100
在这里插入图片描述
-p: 指定运行app的包名
adb shell monkey -p com.package.name 100

-throttle:每个事件之间的时间间隔
adb shell monkey -p com.package.name --throttle 1000 100

-s:seed参数,指定随机生成数的seed值,seed值一致,则事件一致
adb shell monkey -s -p --throttle 1000 100

–ptc-touch:触摸事件,点击事件的占比,除去导航、滑动等操作
adb shell monkey --pct-touch
在这里插入图片描述

–pct-motion:动作事件
adb shell monkey --pct-touch --pct-touch

–pct-trackball:轨迹球事件

–pct-nav:基本导航事件

–pct-syskeys:系统导航,HOME、BACK、拨号、音量

–pct-appswitch:设定启动Activity的事件百分比

–ignore-crashes:忽略崩溃和异常
adb shell monkey --ignore-crashes

–ignore-timeouts:忽略超时
adb shell monkey --ignore-timeouts

-v:日志输出级别

Monkey Script

执行命令

adb shell monkey -f <script_file> <event_count>

<script_file>:脚本文件
<event_count>:执行次数

Dispatch Trackball命令:轨迹球事件
Dispatch Trackball(long downtime, long eventide, int action, float x, float y, float pressure, float size, int metastate, float xprecision, float yprecision, int device, int edgeflags) 其中:

  • long downtime :键最初按下的时间
  • long eventide:时间发生的事件
  • int action:具体操作, 0代表按下,1代表弹起
  • float x,y:坐标点
  • pressure:压力大小(0,1)
  • size:触摸(0,1)
  • device:事件的来源
  • 只许关注action、x、y,其他参数使用默认值就可

DispatchPointer命令:点击事件
DispatchPointer(long downtime, long eventide, int action, float x, float y, float pressure, float size, int metastate, float xprecision, float yprecision, int device, int edgeflags)

  • int action:具体操作, 0代表按下,1代表弹起
  • float x,y:坐标点

DispatchString命令:输入字符串事件
DispatchString(String)

LaunchActivity命令:启动应用
LaunchActivity(package, Activity)

UserWait命令:等待事件
Userwait(1000)

DispatchPress命令:按下键值
DispatchPress(int keycode)

Monkey Script实践

type = user
count=10
speed=1.0
start data >>
#上面内容照抄

LaunchActivity(packageName, MainActivity)
Userwait(2000)
DispatchPointer(10,10,0,100,100,1,1,-1,1,1,0,0)
DispatchPointer(10,10,1,100,100,1,1,-1,1,1,0,0)
DispatchString(test)
Userwait(1000)
DispatchPress(66)
Userwait(1000)
DispatchPointer(10,10,0,400,100,1,1,-1,1,1,0,0)
DispatchPointer(10,10,1,400,100,1,1,-1,1,1,0,0)
Userwait(6000)

将脚本push到/data/local/tmp
执行 adb shell monkey -f script_file 2

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>