Stress test automation code for Android clients using Monkeytest

Source: Internet
Author: User
Tags log log

1, Monkey Command introduction

Monkey is a command-line tool in Android that can be run in the emulator or in the actual device. It sends pseudo-random user event streams (such as key input, touch input, gesture input, etc.) to the system, enabling stress testing of the application under development.

Let's take a look at the monkey command.

100000>e:\monkeylog\monkeyscreenlog.log

This monkey command refers to the creation of 100,000 pseudo-random operations (including touch, keystrokes, gestures, etc.) in the Ctrip.android.view, each interval of 500ms.

2. Monkey Command parameter description

-S
The seed value of the pseudo-random number generator.

Example:-S 600 (if you run monkey again with the same seed value, it will generate the same sequence of events.) )
--throttle
Inserts a fixed delay between events.

Example:--throttle 500 (ms)
-P
If you specify one or several packages with this parameter, monkey will only allow the system to start the activity in those packages. If your application also needs to access activity in other packages (such as choosing to take a contact), those packages need to be specified at the same time. If you do not specify any packages, monkey will allow the system to start the activity in all packages. To specify multiple packages, you need to use multiple-p options, and each-p option can be used for only one package.

Example:-P Ctrip.android.view
--kill-process-after-error
Typically, when Monkey is stopped due to an error, the application that is faulted will continue to be in the running state. When this option is set, the system will be notified of the process of stopping the error. Note that the normal (successful) end, and does not stop the process from starting, the device simply stays in the final state after the end event.
--ignore-timeouts
Typically, monkey stops running when an application has any time-out errors, such as the application not responding dialog box. If this option is set, Monkey will continue to send events to the system until the count is complete.
--ignore-security-exceptions
Typically, when an application has a licensing error (such as starting an activity that requires some permission), Monkey will stop running. If this option is set, Monkey will continue to send events to the system until the count is complete.
-V
Each-V of the command line increases the level of feedback information. 3-V represents the most verbose log level.

Example:-v-v-V 100 (number 100: Indicates the number of test events).

For more information, please refer to: Monkey command parameters

3. Automation example
1#Coding=utf-823‘‘‘4Create on 2014-12-245Python 2.7 for Window6@auther: Tangdongchu7‘‘‘8ImportOs9ImportSys10ImportTime1112ClassMonkeytest ():1314Def__init__(self):15"""Init"""1617#Monkey command, PackageName package name, interval interval unit ms, frequency execution count18DefMonkeyapp (self,packagename,interval,frequency):19Try:Os.popen ("adb shell monkey-p%s--throttle%s--ignore-crashes--ignore-timeouts--ignore-security-exceptions-- Ignore-native-crashes--monitor-native-crashes-v-v-v%s >e:\monkeylog\monkeyscreenlog.log"% (packagename, interval, frequency),‘R‘)21stExceptException,e:22PrintE2324#Export log25DefCopyerrorlog (self):26Try:ANR ="E:\\monkeylog\\anr"28IfNotOs.path.isdir (ANR):29Os.makedirs (ANR)Dontpanic ="E:\\monkeylog\\dontpanic"31IfNotOs.path.isdir (dontpanic):32Os.makedirs (Dontpanic)Tombstones ="E:\\monkeylog\\tombstones"34IfNotOs.path.isdir (Tombstones):35Os.makedirs (Tombstones)Approx. Bugreports ="E:\\monkeylog\\bugreports"37IfNotOs.path.isdir (bugreports):38Os.makedirs (Bugreports)Os.popen ("ADB Pull/data/anr E://MONKEYLOG//ANR",‘R‘)Os.popen ("ADB pull/data/dontpanic e://monkeylog//dontpanic",‘R‘)Os.popen ("ADB pull/data/tombstones E://monkeylog//tombstones",‘R‘)Os.popen ("ADB pull/data/data/com.android.shell/files/bugreports E://monkeylog//bugreports",‘R‘)43ExceptException,e:44PrintE4546DefMain ():47Print""""""484950If__name__=="__main__":51PackageName =‘Ctrip.android.view‘MYAPP =Monkeytest ()Myapp.monkeyapp (packagename,500,100)55#Determine if execution is complete and export the log after execution completes56For Iin range (1, 100000057 Monkeylog = open ( ' e:\monkeylog\monkeyscreenlog.log< Span style= "COLOR: #800000" > ' ) 58 try:59 temp = Monkeylog.read () 60 finally:61  Monkeylog.close () 62 if temp.count ( ' Monkey finished ') >0:63 Myapp.copyerrorlog () break65 else:66 time.sleep (2)         

This completes the automatic execution of the Monkey command and exports the log to the PC for analysis after monkey execution is complete.

4, how to locate the problem through the log

Android platform applications may produce the following four types of crash:

app Layer :

1. Force Close Crash
2. ANR Crash

Native Layer :

3, Tombstone Crash (Native Crash)

Kernel layer :

4, Kernel Panic

Main log file description

ANR Directory: Logs exported from the mobile phone/DATA/ANR to save information on the occurrence of ANR crash;

Dontpanic directory: From the mobile phone/data/dontpanic/exported logs, save the occurrence of kernel panic when the relevant information;

Tombstone directory:/data/tombstones/exported from the mobile phone log, save the error message when tombstone crash occurred;

Dropbox directory: The logs exported from the mobile phone/data/tombstones/, some tombstones error messages intercepted by the Dropbox service;

Bugreports.log: From the mobile phone data/data/com.android.shell/files/bugreports exported logs, save the relevant system information when the exception occurs, can also be extracted through the ADB shell bugreport command;

MonkeyScreenLog.Log: Save Monkey Test process, Application layer error message, when native crash occurs, this file will also be recorded;

Log Analysis method

1, in the MonkeyScreen.Log log file search keyword "Fatal", "Crash", "ANR" to locate the detailed stack information that occurs Crash, through the context to determine the timing of the problem, process PID, etc.

2, check the Dropbox directory for relevant crash log information, mainly concerned about the following 4 types of crash error message: Data_app_wtf,data_app_anr,data_app_crash,system_server_ Watchdog

Log Analysis Example

Stress test automation code for Android clients using Monkeytest

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.