Monkey test for an app in the phone

1. Use an Android phone, configure the environment to connect to the adb tool, and ensure that the adb connection is successful

For specific steps, please refer to ADB installation and common commands_weixin_44240224's Blog-CSDN Blog

2. Because the test is mostly aimed at a specific APP package, you need to know the package name of the test package; you can ask the developer directly, or you can use the adb shell pm list packages command to view all the local packages on the phone.

3. The command to test a specific APP package is adb shell monkey -p <pakage.name>

Parameter explanation:

#package_name: The package name of the application under test

#times: The number of events you want monkey to simulate. For specific events, please refer to the monkey concept mentioned to help you understand

# -p: This parameter is followed by the package name. If this parameter is not specified, the monkey test will randomly select the mobile phone system application test

# -v : This parameter represents the level of detail of the log generated during the monkey test. The level of detail is divided into 3 levels. The specific corresponding parameter writing method is: -v; -vv; -vvv

For the specific scenario, take the reading app in the mobile phone as an example. The returned information is as follows:  

lemon@lemondeMacBook-Air ~ % adb shell monkey -p com.duokan.reader -v 100
  bash arg: -p
  bash arg: com.duokan.reader
  bash arg: -v
  bash arg: 100
args: [-p, com.duokan.reader, -v, 100]
 arg: "-p"
 arg: "com.duokan.reader"
 arg: "-v"
 arg: "100"
data="com.duokan.reader"
:Monkey: seed=1645781479183 count=100
:AllowPackage: com.duokan.reader
: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.category.LAUNCHER;launchFlags=0x10200000;component=com.duokan.reader/.DkReaderActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.duokan.reader/.DkReaderActivity } in package com.duokan.reader
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.duokan.reader/.DkReaderActivity } in package com.duokan.reader
:Sending Touch (ACTION_DOWN): 0:(507.0,1163.0)
:Sending Touch (ACTION_UP): 0:(510.75403,1138.7877)
:Sending Touch (ACTION_DOWN): 0:(609.0,2029.0)
:Sending Touch (ACTION_UP): 0:(600.02954,2029.0245)
:Sending Touch (ACTION_DOWN): 0:(349.0,1765.0)
:Sending Touch (ACTION_UP): 0:(335.8255,1765.1145)
:Sending Touch (ACTION_DOWN): 0:(1030.0,833.0)
:Sending Touch (ACTION_UP): 0:(1024.7245,831.83484)
:Sending Touch (ACTION_DOWN): 0:(882.0,971.0)
:Sending Touch (ACTION_UP): 0:(885.56946,970.6212)
:Sending Touch (ACTION_DOWN): 0:(523.0,1803.0)
:Sending Touch (ACTION_UP): 0:(524.204,1796.2349)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,-2.0)
:Sending Touch (ACTION_DOWN): 0:(477.0,1372.0)
:Sending Touch (ACTION_UP): 0:(477.838,1385.8202)
:Sending Trackball (ACTION_MOVE): 0:(1.0,1.0)
:Sending Touch (ACTION_DOWN): 0:(348.0,1948.0)
:Sending Touch (ACTION_UP): 0:(302.77643,1995.5365)
:Sending Touch (ACTION_DOWN): 0:(562.0,2158.0)
:Sending Touch (ACTION_UP): 0:(576.36725,2175.0)
:Sending Trackball (ACTION_MOVE): 0:(-1.0,1.0)
:Sending Touch (ACTION_DOWN): 0:(151.0,1360.0)
:Sending Touch (ACTION_UP): 0:(155.80309,1360.2347)
:Sending Trackball (ACTION_MOVE): 0:(3.0,-5.0)
:Sending Touch (ACTION_DOWN): 0:(601.0,432.0)
:Sending Touch (ACTION_UP): 0:(612.4258,436.2944)
:Sending Trackball (ACTION_MOVE): 0:(-1.0,-4.0)
:Sending Trackball (ACTION_UP): 0:(0.0,0.0)
:Sending Touch (ACTION_DOWN): 0:(559.0,432.0)
    // Rejecting start of Intent { act=android.intent.action.VIEW dat=https://privacy.mi.com/... cmp=com.android.browser/.BrowserActivity } in package com.android.browser
    // Rejecting start of Intent { act=android.intent.action.VIEW dat=https://privacy.mi.com/... cmp=com.android.browser/.BrowserActivity } in package com.android.browser
Events injected: 100
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=352ms (0ms mobile, 0ms wifi, 352ms not connected)
// Monkey finished

At this time, the connected mobile phone will operate automatically at random 

Guess you like

Origin blog.csdn.net/weixin_44240224/article/details/123096995
Recommended