Android App Stress Test (ii) Monkey Information Automatic collection script "Go"

Source: Internet
Author: User
Tags create directory

Objective:

Monkey introduction of the basic copy of the official introduction, mainly for the convenience of their own inspection. This article focuses on how I automatically collect relevant information when I do monkey, mainly collect monkey test log, cell phone log, mobile phone screen, test mobile phone information, automatically press time to save information. Just a little bit, make up your mind what you want to do, the end of the implementation should have information collected, certain procedures to improve efficiency, saving time. Can groceries look at the beautiful picture, chat ... Oh no, is to learn to improve the aesthetic, communication and enhance the feelings of colleagues ...

Reprint Please specify source: Findyou http://www.cnblogs.com/findyou/p/3936063.html

Directory

1, Findyou's monkey script

2, Findyou script explanation

3. Operation Record

4. Other

1, Findyou's monkey script

1), "script file"

A, configuration file: config.conf

config.conf[appinfo]appcnname=findyouappenname=findyouappversion=v1.0.0packagename=com. Findyou.you

B. script file: Monkey_findyou.bat

@ECHO OFF
ECHO.::::::::::::-----:::------------:--::--::
ECHO.:: Monkey Test::
ECHO.:: findyou::
ECHO.:: Version V1.0.1::
ECHO.:: Time: 2014.08.25::
ECHO.::::::::::::-----:::------------:--::--::
IF not EXIST%~dp0\config.conf GOTO EXIT
ECHO. [INFO] Prepare monkey test
ECHO. [INFO] Read information in config.conf

REM get the package name from the configuration file
for/f "tokens=1,2 delims=="%%a in (config.conf) do (
IF%%a = = PackageName SET packagename=%%b
IF%%a = = Appenname SET appenname=%%b
IF%%a = = appversion SET appversion=%%b
)

REM gets a date in the format: 20140808
SET c_date=%date:~0,4%%date:~5,2%%date:~8,2%
REM gets an hour in the format: 24-hour, 10-point pre-fill 0
SET c_time=%time:~0,2%
if/i%c_time% LSS 10 (
SET c_time=0%time:~1,1%
)
REM combination hours, minutes, seconds, in the form of: 131420
SET c_time=%c_time%%time:~3,2%%time:~6,2%
REM will be the log file name when running point of time
SET logfilename=%c_date%%c_time%


REM Create today's date directory and test app log save directory
IF not EXIST%~dp0\%c_date% MD%~dp0\%c_date%
SET logdir= "%~dp0\%c_date%\%appenname%%appversion%"
IF not EXIST%logdir% (
ECHO. [Exec] Create directory:%c_date%\%appenname%%appversion%
MD%logdir%
)


REM Get Mobile Information, display and save
ADB Shell Cat/system/build.prop>phone.info
for/f "tokens=1,2 delims=="%%a in (phone.info) do (
IF%%a = = Ro.build.version.release SET androidos=%%b
IF%%a = = Ro.product.model SET model=%%b
IF%%a = = Ro.product.brand SET brand=%%b
)
del/a/f/q Phone.info
ECHO. [INFO] Read phone information
ECHO. Mobile Brand:%brand%
ECHO. Phone Model:%model%
ECHO. System version: Android%androidos%
ECHO. Phone info > "%logdir%\%logfilename%_%model%.txt"
ECHO. Mobile Brand:%brand%>> "%logdir%\%logfilename%_%model%.txt"
ECHO. Phone model:%model%>> "%logdir%\%logfilename%_%model%.txt"
ECHO. System version: Android%androidos%>> "%logdir%\%logfilename%_%model%.txt"

ECHO.
ECHO. [Exec] Use Logcat to empty the phone log
ADB logcat-c
REM ECHO. [INFO] Pause for 2 seconds ...
Ping-n 2 127.0.0.1>nul
ECHO.
ECHO. [INFO] starts executing the monkey command
REM ECHO. [INFO] Force the app to be closed for testing
ADB shell am force-stop%packagename%

::::::::::----Monkey::-----------:---::::-::.
:::::::::::: Modify policy only in this area::,::;:::------.
ECHO. [Exec] adb shell monkey-p%packagename%-S%c_time%--throttle 500-v-v-v 10000

ADB shell monkey-p%packagename%-S%c_time%--throttle 500-v-v-v 10000>%logdir%\%logfilename%_monkey.log

:::::::::::: Modify policy only in this area::,::;:::------.
::::::::::::--: (:::::: ":": ")":::-::::.:: ":"..::;:: ".
ECHO. [INFO] Execution Monkey command end
ECHO.

ECHO. [Exce] Phone screenshot
ADB Shell Screencap-p/sdcard/monkey_run_end.png
ECHO. [INFO] Copy screenshots to PC
ADB pull/sdcard/monkey_run_end.png%logdir%
CD%logdir%
ren monkey_run_end.png%logfilename%.png

ECHO.
ECHO. [Exec] exporting logs using Logcat
ADB logcat-d >%logdir%\%logfilename%_logcat.log

REM ECHO.
REM ECHO. [Exec] Export traces file
REM adb Shell Cat/data/anr/traces.txt>%logfilename%_traces.log


REM to expand, upload logs to server

: EXIT
ECHO.
ECHO. [INFO] Please press any key to close the window ...

Pause>nul

Note: When you save the bat note for the file format ANSI ha, windows you understand

2), "How to use"

A, save the script: Copy the config.conf, Monkey_findyou.bat content in this article is saved in the same directory

b, modify the configuration: Modify the content in the config.conf for the app you need to test the corresponding information

C, execute the script: double-click Monkey_findyou.bat can

★ Warm hint ★a, environment variable: ADB command executable (need to install Android SDK, do not install the configuration please Baidu or Google) B, save the script: The directory is not too deep, and suggested for the English folder, do not have spaces or special characters C, Phone Connection: This version of the script is not connected to the computer's multi-Android device to detect, only a single phone to test and operate

2, Findyou script explanation

1), Reason and history introduction

Novice Stage: Monkey test, basically run a command, and then the monkey after the execution of the information returned to save, directly to research and development. Because information is not complete, research and development positioning also takes a long time, troubleshooting is too difficult. The complaint is not professional ah, what what ...

The second stage: first increase the Logcat log information export, the execution result handset screenshot. Post-sleep is necessary to increase the app's own printing and capture information about the export.

The third stage: because occasionally to run monkey, too much too many times, very annoying, manual export data is also very painful. Because of the constant duplication of work, the thinking is automated. When choosing a language, I think Python is powerful, the introduction of Python good choice, in-depth thinking, is not to execute a command, a few files, batch processing is very strong, and not everyone is loaded Python ha. So the simplest method is used. The published script has lost the app's own log collection, as the data files generated by the app are different from their own business logs, so they are truncated. It is also the ADB pull command, if necessary, since the script has been added.

2), script explanation

A, Core: Monkey command

ADB shell monkey-p%packagename%-S%c_time%--throttle 100-v-v-v 10000-p%packagename% Specifies the test package name,%packagename% the value of the variable from the packagename corresponding to the file config.conf. -S%c_time% %c_time% to execute the script at the time (hours, minutes, seconds), the time is the value of the random purpose, but also for the subsequent need to simulate the test to provide an event sequence. --throttle 100 Represents the interval, that is, the time interval for each operation, and the meaning of this command is to increase the time interval of 500ms. -v-v-V 10000 -v-v-V Log Levels Level 2, the most detailed log, includes the selected/Unchecked activity information in the test. 10000 executes 10,000 random events.

★ Warm Tips ★

①, Monkey command area labeling, can be determined on demand,%packagename% represents the package name you need to test, others can increase or decrease the monkey parameter.

②, example: adb shell monkey-p%packagename%-S%c_time%--throttle 10000--ignore-crashes-v-v-v

③, Monkey here do not do too much explanation, online has a lot of monkey test strategy Introduction. BAT in other related methods of operation of the script basically have annotations and explanations, I believe you can understand.

B, configuration files

config.conf[appinfo]appcnname=findyouappenname=findyouappversion=v1.0.0packagename=com. Findyou.you

①, Appcnname: Temporarily unused in this script

②, Appenname: The app name to be tested, recommended in English or pinyin, use this value in many places

③, appversion: App version number to be tested, no spaces, bat script does not handle

④, PackageName: App version to test package name

★ Warm Tips ★

①, App 3rd, 4 information can be obtained from the installation apk using the AAPT command, please see my note, "Android Test efficiency batch script" http://www.cnblogs.com/findyou/p/3785618.html

3), information collection Automation implementation

monkey_findyou.bat Results F:\Monkey\20140808\FindyouV1.0.0 20140825181801.png 20140825181801_logcat.log 2 0140825181801_monkey.log 20140825181801_sm-n9008v.txt

①, monkey after the mobile phone screenshot: 20140825181801.png

②, monkey when mobile phone log: 20140825181801_logcat.log

③, monkey test Result: 20140825181801_monkey.log

④, measured cell phone information: 20140825181801_sm-n9008v.txt

★ Warm Tips ★

*, each execution monkey will automatically collect relevant information to generate the above four files, the file name is the time of execution.

*, analyze the log file, whether there is an exception keyword: CRASH, ANR, exception, and so on, want to lazy to pack four of documents to research and development positioning can, but still suggest that they learn to analyze.

*, if there is a need to test stress test several times, how many times do you want to do so, the following provides a thought

①, delete the last line of the Monkey_findyou.bat script "Pause>nul", Save

②, set the phone to never lock the screen, or install the Auto Unlock app (script execution to tune the app)

③, Scheduled Tasks for Windows Execute Monkey_findyou.bat

3. Operation Record

1), double-click Execute Monkey_findyou.bat

2), script execution information

3), Output results

4. Other

This basic has been completed, the next time to share the monkey log, cell phone log automatic analysis. Cases:

Very simple principle, search keywords, simple judgment, another day to complete an article, the script upload share.

Other boost efficiency bat script share: Android test boost efficiency batch script

Reprint Please specify source: findyou http://www.cnblogs.com/findyou/p/3936063.html

Android App Stress Test (ii) Monkey Information Automatic collection script "Go"

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.