Android App Stress Test Monkeyrunner

Source: Internet
Author: User
Tags python script

Android App Stress test

The first part of the background
1. Why stress tests are carried out?
2. When do stress tests start?
Part Two theory
1. Manual Test Scenario
2. Automated test creation
3. Monkey Tools
4. ADB command
5. Monkey Script
6. Monkey Runner
7. Stress test Results Analysis
1. What is crash? (Crash Ben Collapse)
2. What is ANR? (No response)
Part III Practice
1. Stress test practice for an app
2. Application of Monkey Advanced parameters
3. Crash result extraction
4. ANR Results Extraction
5. Monkey Script Instance
6. Monkeyrunner instances

The first part of the background
1. Why stress tests are carried out?
Improve product stability
Increase the retention rate of products
Increase Product utilization
2. When do stress tests start?
After the first round of functional test passed
The night after work.

Part Two theory
1. Manual Test Scenario
Chat steps: Find--add--Chat
TouchInput---keyevent---touchsearch---touchname---touchfriend---keyevent
1. What is Monkey? " Monkey is the ability to send pseudo-random user events "
Where's the 2.MOnkey? " In any Android phone system "
3. What is ADB? "Android Debug Bridge"
Establish a hard connection/use USB cable;
Establish a soft connection/use ADB.
4. What is Monkeyscript?
"Monkeyscript is a set of commands that can be recognized by monkey."
"Monkeyscript can perform repetitive fixed operations"
5. What is Monkeyrunner?
"Monkeyrunner provides a series of APIs."
"Monkeyrunner can complete analog events and operations"
6. What is the difference between monkey and Monkeyrunner?
"Monkey generates pseudo-random events for users or systems in the ADB shell"
"Monkeyrunner defines specific commands and event control devices through the API"
7.MonkeyRunner APIs
1. Monkeyrunner: "Used to connect the device or simulator"
2. Monkeydevice: "Provide installation > uninstall application, send simulation event"
3. Monkeyimage: "Complete image preservation, and contrast operation"
What is the test type of 8.MonkeyRunner?
Multi-Device control
Functional Testing
Regression test
9. Stress test results?
1. CRASH: That is, the application in use, the abnormal exit.
2. Anr:application not responding application is unresponsive.

Logcat is a command-line tool in Android that can be used to get log information for a program

Part III Practice
1. Stress test practice for an app
Pressure test process steps:
1. In the Mobile developer options, select USB Debug.
2. Confirm that the phone and computer are connected successfully. Confirm Soft Connect command in cmd, enter ADB devices
3. Install the test app use the command to install "adb install package.apk" < need to put the installation package in Platform-tools >
4. Pressure test, send pressure command adb shell Monkey 1000< 1000 this random test >
When you see events injected:100 the successful execution is complete,
5. Get the App package name "adb Logcat | grep START "
Windows needs to execute "adb shell" into the shell before executing "logcat | grep START "
Click the app you want to test to see the package name you want to test. Com.android.bbkcalculator "
6. Give the specified package a big pressure "adb shell monkey-p com.android.bbkcalculator 1000"

2. Application of Monkey Advanced parameters
1. Throttle parameter "Specify the interval between events"
adb shell Monkey--throttle <milliseconds number of milliseconds >
2. Seed parameters
Seed: Specifies the seed value of a randomly generated number and uniquely specifies a random sequence of operations
The so-called stochastic, in fact, is also a regular, specific seed value, corresponding to the only random sequence of operations.
The number after-S is the seed value
3. Touch Events
Set touch event percentage "adb Shell monkey--pct-touch <percent>"
To add the-v parameter, you can list the details of the random operation
View Event percentages:0 represents a touch event.
4. Action Events
Set percentage of action events "adb shell Monkey--pct-motion <percent>"
5. Trackball Events
Set trackball event percentage "adb Shell monkey--pct-trackball <percent>"
6. Basic Navigation Events
Set basic navigation event percentage, input device up or down
"adb shell monkey--pct-nav <percent>"
7. Main navigation Events
Set main navigation event percentage, compatible Middle key, return key, menu button
8. System Navigation Events
Set system navigation event percentage, HOME, Back, dial and volume keys
"adb shell monkey--pct-syskeys <percent>"
9. Start Activity Events
Set the percentage of events that start activity
"adb shell monkey--pct-appswitch <percent>"
10. Infrequently used Events
Set percentage of infrequently used events
"adb shell monkey--pct-anyevent <percent>"
11. Rush Event
Ignoring the rush and exception
"adb shell monkey--ignore-crashes <event-count>"
12 Timeout Events
Ignore Timeout events
"adb shell monkey--ignore-timeouts <event-count>"

3. Crash result extraction
1. After crash, the log information in cmd, crash below, is assigned to the development.
2. After the crash, you can record the seed value, so that the collapse of the replay operation.
4. ANR Results Extraction
1. Extract the exception information for ANR
2. Check the log information below the ANR
3. The ANR, logs, and seed values can be reproduced later.
4. You can also view the ANR information by looking at the file
First use the ADB shell to enter the shell of the Android system,
Use the CD/DATA/ANR directory to find the ANR files, such as Trace.txt. Open to see the ANR information.
5. Monkey Script Instance
Complete some repetitive fixed operations, using Monkeyscript
command to execute the Monkey script: "adb shell monkey-f <scriptfile script file > <event-count execution times >"
1.DispatchTrackball command,
Trackball Events
Dispatchtrackball (Long downtime,long eventide,int action,float x,float y, float pressure, float size,
int metastate,float xprecision, float yprecision,int device,int edgeflags)
Action 0 represents press, 1 for bounce, x and y for coordinate points
Commands need to be used in pairs, one press 0, one bouncing up to 1,
2.DispatchPointer command,
Click events
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)
Action 0 represents press, 1 for bounce, x and y for coordinate points
Commands need to be used in pairs, one press 0, one bouncing up to 1,
3.DispatchString command,
Input string Event
Dispatchstring (String text)
4.LaunchActivity command
Launch the App
Launchactivity (package,activity)
5.UserWait command
Wait for event
Userwait (1000)//wait 1 seconds
6. Dispatchpress command
Press the key value
dispatchpress (int keycode)//keycode 66 return car Key
6. Monkeyrunner instances
The Monkeyruner script is written for the Python language
FOM Com.android.monkeyrunner Import Monkeyrunner
1. Monkeyrunner Api-alert
Warning Box
void alert (String message,string title, String oktitle)
Example: Monkeyrunner.alert (' Hello monkey friend ', ' This is a title ', ' OK ')
2. Monkeyrunner api-waitforconnection
Wait for the device to connect, have multiple device IDs, and need to indicate which device is specific.
Waitforconnection (float timeouts,string DeviceID)
3. Monkeydevice Api-drag
Drag
Drag (tuple start,tuple end, float duration, integer steps)
Start start position,
End End Position,
Duration the duration of the gesture,
Step interpolation point, default 10.
4. Monkeydevice api-press
Keys
Press (string keycode,dictionary type)
KeyCode name, down, up, down_and_up
5. Monkeydevice api-startactivity
Launch the App
StartActivity (package+ '/' +activity)
6. Monkeydevice Api-touch
Click
Touch (integer x, integer y, integer type)
X and Y are axes
Type:down, up, down_and_up
7. Monkeydevice Api-type
Input
Type (String message)
8. Monkeydevice Api-takesnapshot
Screen Cutting
Monkeyimage Takesnapshot ()
9. Monkeyimage Api-sameas
Image comparison
Boolean Sameas (Monkeyimage other, float percent)
Ten. Monkeyimage Api-writetofile
Save image File
void WriteToFile (string path, string format)
Path: Paths to file storage
Format: Image file formats png, JPG, etc.
Monkeyrunner.sleep (1)//Add wait Time

1//example of a Python script for Monkeyrunner2 #-*-utf-8-*-3  fromCom.android.monkeyrunnerImportMonkeyrunner,monkeydevice,monkeyimage4 #Connecting Devices5device = Monkeyrunner.waitforconnection (3,"192.168.110.120:2525")6 #Launch App7Device.startactivity ("com.example.testbrowser2/com.example.testbrowser2.myapplication.mainactivity")8Monkeyrunner.sleep (2)9 #Click the Search input boxTenDevice.touch (100,100,"down_and_up") OneMonkeyrunner.sleep (1) A #Enter Query terms -Device.type ('Test input ABCD') -Monkeyrunner.sleep (1) the #Click Enter -Device.press ("Keycode_enter","down_and_up") -Monkeyrunner.sleep (1) - #Click the Search button +Device.touch (400,100,"down_and_up") -Monkeyrunner.sleep (5) + #  AImage =device.takesnapshot () atImage.writetofile ("F://image/test.png","PNG") - #Click the Clear button -Device.touch (300,100,"down_and_up") -Monkeyrunner.sleep (3) -Using the Uiautomatorviewer.bat of the Androidsdk\tools directory, launch the software to get the coordinate position of the phone's button.

Android App Stress Test Monkeyrunner

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.