Monkey详解(限制型指令篇)

(六)限制型指令

Monkey通过两个参数来限制随机事件。
(1)-p:将随机事件限制在指定的package内。
若不使用-p参数,monkey则可以启动系统内所有Activity。

C:\Users\XXXX>adb shell monkey -v -p com.breakloop.butterknifedemo 10
:Monkey: seed=1503635798742 count=10
:AllowPackage: com.breakloop.butterknifedemo
: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.breakloop.butterknifedemo/.Mai
nActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.breakloop.butterknifedemo/.MainActivity } in pac
kage com.breakloop.butterknifedemo
: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 com.breakloop.butterknifedemo -p com.brea
kloop.app 20
:Monkey: seed=1503656781247 count=20
:AllowPackage: com.breakloop.butterknifedemo
:AllowPackage: com.breakloop.app
: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.breakloop.butterknifedemo/.Mai
nActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.breakloop.butterknifedemo/.MainActivity } in pac
kage com.breakloop.butterknifedemo
: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:将随机事件限制在指定的Intent.Categroy内。
若不使用-c参数,Monkey将选择Intent.Category.Launcher和Intent.Category.Monkey里的activity,作为测试对象。

例如,对Intent.Category为“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=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10200000;component=com.breakloop.butterknifedemo/.Mai
nActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.breakloop.butterknifedemo/.MainActivity } in pac
kage com.breakloop.butterknifedemo
: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=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 Trackball (ACTION_MOVE): 0:(0.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-1.0)
    // Allowing start of Intent { act=com.google.zxing.client.android.SCAN cmp=c
om.gemalto.qrcodelib/com.journeyapps.barcodescanner.CaptureActivity } in package
 com.gemalto.qrcodelib
: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的事件类指令用法。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值