(六)限制型指令
Monkey通过两个参数来限制随机事件。
(1)-p:将随机事件限制在指定的package内。
若不使用-p参数,monkey则可以启动系统内所有Activity。
C:\Users\XXXX>adb shell monkey -v -p 10
:Monkey: seed=1503635798742 count=10
:AllowPackage:
:IncludeCategory:
:IncludeCategory:
// 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=;category=
;launchFlags=0x10200000;component=/.Mai
nActivity;end
// Allowing start of Intent { act= cat=[
] cmp=/.MainActivity } in pac
kage
:Sending Touch (ACTION_DOWN): 0:(946.0,544.0)
:Sending Touch (ACTION_UP): 0:(934.8523,552.389)
:Sending Touch (ACTION_DOWN): 0:(471.0,311.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=53ms (0ms mobile, 0ms wifi, 53ms not connected)
// Monkey finished
C:\Users\XXXX>
若有多个package,则需要使用多个-p,每个-p后面跟随一个package.
C:\Users\XXXX>adb shell monkey -v -p -p
20
:Monkey: seed=1503656781247 count=20
:AllowPackage:
:AllowPackage:
:IncludeCategory:
:IncludeCategory:
// 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=;category=
;launchFlags=0x10200000;component=/.Mai
nActivity;end
// Allowing start of Intent { act= cat=[
] cmp=/.MainActivity } in pac
kage
:Sending Touch (ACTION_DOWN): 0:(482.0,1730.0)
:Sending Touch (ACTION_UP): 0:(488.29337,1735.2903)
:Sending Touch (ACTION_DOWN): 0:(488.0,498.0)
:Sending Touch (ACTION_UP): 0:(472.84113,507.77313)
:Sending Touch (ACTION_DOWN): 0:(688.0,357.0)
:Sending Touch (ACTION_UP): 0:(679.2682,357.4477)
:Sending Trackball (ACTION_MOVE): 0:(-1.0,0.0)
Events injected: 20
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=194ms (0ms mobile, 0ms wifi, 194ms not connected)
// Monkey finished
C:\Users\XXXX>
注:若package A中调用了package B中的activity,则-p package A的同时,也需要-p package B.
(2)-c:将随机事件限制在指定的内。
若不使用-c参数,Monkey将选择和里的activity,作为测试对象。
例如,对为“abc”的Activity做10次随机性事件
C:\Users\XXXX>adb shell monkey -v -c abc 10
:Monkey: seed=1503639596178 count=10
:IncludeCategory: abc
// 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=;category=
;launchFlags=0x10200000;component=/.Mai
nActivity;end
// Allowing start of Intent { act= cat=[
] cmp=/.MainActivity } in pac
kage
:Sending Trackball (ACTION_MOVE): 0:(-3.0,-1.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=364ms (0ms mobile, 0ms wifi, 364ms not connected)
// Monkey finished
C:\Users\XXXX>
与-p类似,若有多个Categroy,则需要使用多个-c,每个-c后面跟随一个Category,相互之间为或的关系。
C:\Users\XXXX>adb shell monkey -c abc -c bcde -v 100
:Monkey: seed=1503470839433 count=100
:IncludeCategory: abc
:IncludeCategory: bcde
// 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=;category=
;launchFlags=0x10200000;component=/.MainActivit
y;end
// Allowing start of Intent { act= cat=[
] cmp=/.MainActivity } in package com
.
:Sending Trackball (ACTION_MOVE): 0:(0.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-1.0)
// Allowing start of Intent { act= cmp=c
/ } in package
:Sending Touch (ACTION_DOWN): 0:(546.0,413.0)
:Sending Touch (ACTION_UP): 0:(546.77246,469.73663)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(1.0,0.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,1.0)
:Sending Touch (ACTION_DOWN): 0:(718.0,568.0)
:Sending Touch (ACTION_UP): 0:(716.4752,570.05597)
:Sending Touch (ACTION_DOWN): 0:(1163.0,278.0)
:Sending Touch (ACTION_UP): 0:(1160.74,292.6258)
:Sending Touch (ACTION_DOWN): 0:(1784.0,104.0)
:Sending Touch (ACTION_UP): 0:(1802.4581,32.097107)
:Sending Touch (ACTION_DOWN): 0:(767.0,247.0)
:Sending Touch (ACTION_UP): 0:(845.0654,240.24954)
Events injected: 100
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=984ms (0ms mobile, 0ms wifi, 984ms not connected)
// Monkey finished
C:\Users\XXXX>
我们将在之后,总结Money的事件类指令用法。