Monkey详解(事件型指令篇)

(七)事件型指令
事件类型指令可实现四个主要功能。

(1)复现随机事件

Monkey最大的特点就是伪随机。之所以加个“伪”字,是因为该随机事件可进行复现。
我们每次执行一组随机事件,系统都会给一个随机的ID,称之为seed。例如

C:\Users\XXXX>adb shell monkey -p com.breakloop.butterknifedemo -v 100
:Monkey: seed=1503779100077 count=100
:AllowPackage: com.breakloop.butterknifedemo
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
....
## Network stats: elapsed time=83ms (0ms mobile, 0ms wifi, 83ms not connected)
// Monkey finished

C:\Users\XXXX>

若我们想将该组随机事件再次执行一遍,则使用-s+seed+count即可。

C:\Users\yisong>adb shell monkey -v -s 1503779100077 100
:Monkey: seed=1503779100077 count=100
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
...
## Network stats: elapsed time=588ms (0ms mobile, 0ms wifi, 588ms not connected)

// Monkey finished

C:\Users\yisong>

除了执行事件不同,其他都与之前一样。

那么问题来了
(a)如果seed后的count,与之前不同,执行结果会如何?
若count变小,则从前往后,执行count个事件。
若count变大,则在执行完后,补充执行差数个随机事件。
(b)seed何时过期?
重新连接设备,kill-server&start-server,重启手机,都不会对seed有影响。

(2)指定事件间隔

在相邻的两条随机事件之间,默认没有事件间隔。因此,有时会引起随机事件的注入失败。

:Sending Touch (ACTION_DOWN): 0:(736.0,455.0)
    // Injection Failed
:Sending Touch (ACTION_UP): 0:(736.2039,467.69113)
    // Injection Failed
:Sending Flip keyboardOpen=false
Got IOException performing flipjava.io.IOException: write failed: EINVAL (Invali
d argument)
    // Injection Failed
:Sending Touch (ACTION_DOWN): 0:(352.0,1698.0)
    // Injection Failed
:Sending Touch (ACTION_UP): 0:(349.23996,1686.784)
    // Injection Failed
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-4.0)
:Sending Trackball (ACTION_UP): 0:(0.0,0.0)
:Sending Touch (ACTION_DOWN): 0:(788.0,1048.0)
    // Injection Failed
:Sending Touch (ACTION_UP): 0:(780.9308,1044.052)
    // Injection Failed
:Sending Trackball (ACTION_MOVE): 0:(0.0,-2.0)

为了避免这类情况,须在事件间添加“等待”。使用参数–throttle+时间间隔。
throttle(油门)?应该命名为刹车吧。
需要说明的是
(a)参数前是两个“-”
(b)时间单位为毫秒

:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.vmall.client/.activity.VmallWa
pActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.vmall.client/.activity.VmallWapActivity } in pac
kage com.vmall.client
Sleeping for 1000 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,-3.0)
:Sending Trackball (ACTION_DOWN): 0:(0.0,0.0)
:Sending Trackball (ACTION_UP): 0:(0.0,0.0)
Sleeping for 1000 milliseconds
    // Allowing start of Intent { cmp=com.vmall.client/.activity.PolicyWebActivi
ty } in package com.vmall.client
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Touch (ACTION_DOWN): 0:(139.0,398.0)
:Sending Touch (ACTION_MOVE): 0:(157.42459,406.12418)
:Sending Touch (ACTION_MOVE): 0:(175.66505,407.0996)
:Sending Touch (ACTION_MOVE): 0:(185.49532,419.4165)
:Sending Touch (ACTION_MOVE): 0:(199.77296,435.93414)
:Sending Touch (ACTION_MOVE): 0:(215.76842,453.50436)
:Sending Touch (ACTION_MOVE): 0:(232.69334,470.774)
:Sending Touch (ACTION_MOVE): 0:(254.05827,476.62515)
:Sending Touch (ACTION_MOVE): 0:(262.36322,481.53244)
:Sending Touch (ACTION_UP): 0:(281.79745,489.0132)
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU

注:从log来看,并不是所有的事件后都有“等待”。个人感觉,是在事件无法第一时间得到响应时,才去等待。

(3)指定某类事件所占比例

那么我们都有哪些事件呢?
各个事件都代表什么操作?
如果不设置事件比例,有没有默认的比例?
我们来一一解释。

先来看一组随机事件LOG。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v 10
:Monkey: seed=1503647257950 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 15.0%
//   1: 10.0%
//   2: 2.0%
//   3: 15.0%
//   4: -0.0%
//   5: -0.0%
//   6: 25.0%
//   7: 15.0%
//   8: 2.0%
//   9: 2.0%
//   10: 1.0%
//   11: 13.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.android.findmyphone/.ui
.FindMyPhoneActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.android.findmyphone/.ui.FindMyPhoneActivi
ty } in package com.huawei.android.findmyphone
:Sending Touch (ACTION_DOWN): 0:(236.0,163.0)
:Sending Touch (ACTION_UP): 0:(247.74335,163.03857)
:Sending Touch (ACTION_DOWN): 0:(819.0,1411.0)
:Sending Touch (ACTION_UP): 0:(825.0237,1402.9965)
:Sending Touch (ACTION_DOWN): 0:(745.0,1572.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5113ms (0ms mobile, 0ms wifi, 5113ms not connecte
d)
// Monkey finished

其中有一个Event percentages。可见,如果不使用–pct-XXXX指令,则按照默认比例触发随机事件。只是,不知道索引对应的事件是什么。

按照参数,可以分为八类。
(a)–pct-touch:触摸事件。即在某一位置的Down-Up(手指的放下和抬起)事件。Down(ACTION_DOWN)和Up(ACTION_UP)的坐标临近,但并非相同。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v --pct-touch 100 10
:Monkey: seed=1503671202592 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 100.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.gemalto.qrcodelib/.MainActivit
y;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.gemalto.qrcodelib/.MainActivity } in package com
.gemalto.qrcodelib
:Sending Touch (ACTION_DOWN): 0:(186.0,781.0)
:Sending Touch (ACTION_UP): 0:(181.72902,780.3934)
:Sending Touch (ACTION_DOWN): 0:(600.0,384.0)
:Sending Touch (ACTION_UP): 0:(609.29193,385.8893)
:Sending Touch (ACTION_DOWN): 0:(786.0,1742.0)
:Sending Touch (ACTION_UP): 0:(782.567,1737.6458)
:Sending Touch (ACTION_DOWN): 0:(733.0,1538.0)
:Sending Touch (ACTION_UP): 0:(742.7612,1545.8889)
:Sending Touch (ACTION_DOWN): 0:(176.0,1538.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5093ms (0ms mobile, 0ms wifi, 5093ms not connecte
d)
// Monkey finished

(b)–pct-motion:动作事件。以Down(ACTION_DOWN)开始,Up(ACTION_UP)结尾,中间至少有一次Move(ACTION_MOVE)。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-motion 100 10
:Monkey: seed=1503775969786 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503775969786
// Event percentages:
//   0: 0.0%
//   1: 100.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.android.remotecontrolle
r/.StartActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.android.remotecontroller/.StartActivity }
 in package com.huawei.android.remotecontroller
Sleeping for 1000 milliseconds
    // Allowing start of Intent { cmp=com.huawei.android.remotecontroller/.app.W
elcomeActivity } in package com.huawei.android.remotecontroller
    // activityResuming(com.huawei.android.remotecontroller)
:Sending Touch (ACTION_DOWN): 0:(241.0,1334.0)
:Sending Touch (ACTION_MOVE): 0:(245.10721,1333.8828)
:Sending Touch (ACTION_MOVE): 0:(246.83798,1331.2542)
:Sending Touch (ACTION_MOVE): 0:(248.75221,1324.734)
:Sending Touch (ACTION_MOVE): 0:(249.26602,1323.9482)
:Sending Touch (ACTION_MOVE): 0:(251.57216,1317.7059)
:Sending Touch (ACTION_MOVE): 0:(255.50874,1314.2244)
:Sending Touch (ACTION_UP): 0:(259.62653,1307.603)
Sleeping for 1000 milliseconds
:Sending Touch (ACTION_DOWN): 0:(1031.0,1108.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=2060ms (0ms mobile, 0ms wifi, 2060ms not connecte
d)
// Monkey finished

(c)–pct-trackball:轨迹球事件。即单纯的Move(ACTION_MOVE)。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-trackball 100 10
:Monkey: seed=1503665474331 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503665474331
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 100.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.yunos.cloudkit.demo/.MainActiv
ity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.yunos.cloudkit.demo/.MainActivity } in package c
om.yunos.cloudkit.demo
Sleeping for 1000 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(-1.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,-3.0)
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=1045ms (0ms mobile, 0ms wifi, 1045ms not connecte
d)
// Monkey finished

(d)–pct-nav:基本导航事件。即来自于方向输入设备的上下左右操作。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-nav 100 10
:Monkey: seed=1503699935813 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503699935813
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 100.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.gto.paltesttoolui/com.gto.tsm.
instrumentation.EmmaInstrumentation%24InstrumentedActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.gto.paltesttoolui/com.gto.tsm.instrumentation.Em
maInstrumentation$InstrumentedActivity } in package com.gto.paltesttoolui
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT
:Sending Key (ACTION_UP): 22    // KEYCODE_DPAD_RIGHT
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT
:Sending Key (ACTION_UP): 22    // KEYCODE_DPAD_RIGHT
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 20    // KEYCODE_DPAD_DOWN
:Sending Key (ACTION_UP): 20    // KEYCODE_DPAD_DOWN
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 21    // KEYCODE_DPAD_LEFT
:Sending Key (ACTION_UP): 21    // KEYCODE_DPAD_LEFT
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 21    // KEYCODE_DPAD_LEFT
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5116ms (0ms mobile, 0ms wifi, 5116ms not connecte
d)
// Monkey finished

(e)–pct-majornav:主导航事件。即Navigation Bar的确认,菜单,返回键等。

C:\Users\XXXX>adb shell monkey --throttle 1000 -v -v --pct-majornav 100 10
:Monkey: seed=1503700822988 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503700822988
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 100.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.android.settings/.HWSettings;e
nd
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.android.settings/.HWSettings } in package com.an
droid.settings
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 23    // KEYCODE_DPAD_CENTER
:Sending Key (ACTION_UP): 23    // KEYCODE_DPAD_CENTER
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU
:Sending Key (ACTION_UP): 82    // KEYCODE_MENU
Sleeping for 1000 milliseconds
:Sending Key (ACTION_DOWN): 23    // KEYCODE_DPAD_CENTER
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=5100ms (0ms mobile, 0ms wifi, 5100ms not connecte
d)
// Monkey finished

(f)–pct-syskeys:系统按键事件。即系统保留按键,如HOME键,BACK键,拨号键,挂断键,音量键等。

C:\Users\XXXX>adb shell monkey -v -v --pct-syskeys 100 10
:Monkey: seed=1503762438503 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503762438503
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 100.0%
//   9: 0.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.phoneservice/.ui.HelpCe
nterActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.phoneservice/.ui.HelpCenterActivity } in
package com.huawei.phoneservice
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 24    // KEYCODE_VOLUME_UP
    // Allowing start of Intent { cmp=com.huawei.phoneservice/com.huawei.phonese
rviceuni.start.UserAgreementActivity } in package com.huawei.phoneservice
:Sending Key (ACTION_UP): 24    // KEYCODE_VOLUME_UP
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 25    // KEYCODE_VOLUME_DOWN
:Sending Key (ACTION_UP): 25    // KEYCODE_VOLUME_DOWN
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 25    // KEYCODE_VOLUME_DOWN
:Sending Key (ACTION_UP): 25    // KEYCODE_VOLUME_DOWN
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 24    // KEYCODE_VOLUME_UP
:Sending Key (ACTION_UP): 24    // KEYCODE_VOLUME_UP
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 24    // KEYCODE_VOLUME_UP
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=765ms (0ms mobile, 0ms wifi, 765ms not connected)

// Monkey finished

(g)–pct-appswitch:应用启动事件

C:\Users\XXXX>adb shell monkey -v --pct-appswitch 100 3
:Monkey: seed=1503724767031 count=3
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 100.0%
//   10: 0.0%
//   11: 0.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.cate
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.fans/.activity.MainAct
vity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.i
tent.category.LAUNCHER] cmp=com.huawei.fans/.activity.MainActivity } in package
com.huawei.fans
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.cate
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.appmarket/.MainActivit
;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.i
tent.category.LAUNCHER] cmp=com.huawei.appmarket/.MainActivity } in package com
huawei.appmarket
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.cate
ory.LAUNCHER;launchFlags=0x10200000;component=com.android.soundrecorder/.SoundR
corder;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.i
tent.category.LAUNCHER] cmp=com.android.soundrecorder/.SoundRecorder } in packa
e com.android.soundrecorder
Events injected: 3
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=75ms (0ms mobile, 0ms wifi, 75ms not connected)
// Monkey finished

(h)–pct-anyevent:其他未提及事件。该事件可能包含其他上述事件。

C:\Users\XXXX>adb shell monkey -v -v --pct-anyevent 100 10
:Monkey: seed=1503761055148 count=10
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Seeded: 1503761055148
// Event percentages:
//   0: 0.0%
//   1: 0.0%
//   2: 0.0%
//   3: 0.0%
//   4: -0.0%
//   5: -0.0%
//   6: 0.0%
//   7: 0.0%
//   8: 0.0%
//   9: 0.0%
//   10: 0.0%
//   11: 100.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.huawei.health/.MainActivity;en
d
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.huawei.health/.MainActivity } in package com.hua
wei.health
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 549    // 549
:Sending Key (ACTION_UP): 549    // 549
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 507    // 507
:Sending Key (ACTION_UP): 507    // 507
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 362    // 362
:Sending Key (ACTION_UP): 362    // 362
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 673    // 673
:Sending Key (ACTION_UP): 673    // 673
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 25    // KEYCODE_VOLUME_DOWN
Events injected: 10
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=691ms (0ms mobile, 0ms wifi, 691ms not connected)

// Monkey finished

仔细观察各个事件的Log,不难发现:
(I)所有随机事件,若count>0,第一个事件永远是appswitch。必须要有一个activity作为操作对象!!
(II)将某种事件所占百分比,调至100,可得出事件索引对应关系。
0–> –pct-touch
1–> –pct-motion
3–> –pct-trackball
6–> –pct-nav
7–> –pct-majornav
8–> –pct-syskeys
9–> –pct-appswitch
11–> –pct-anyevent

(III)若使用一个-v,ACTION_MOVE事件或KEYCODE_DPAD_XXXX不会显示在LOG中。

(4)执行脚本

使用参数-f来指定脚本path。

adb shell monkey -f c:\d\test 100

文件可用没有后缀名。
注:此时count=100,是指将该脚本执行100次。

对于脚本的编写,我们将用单独的篇幅来讲解。

  • 1
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值