1. 程式人生 > >Execute Monkey and Record Log and Screen

Execute Monkey and Record Log and Screen

Here is an example to do monkey test and record log and device screen.

SET REPEAT_TIMES=10

SET ADB_PREFIX=adb
SET APP_NAME=MMS
SET APK_PKG_NAME=com.wsandroid.suite
SET APK_ACTIVITY_LAUNCH=com.mcafee.app.LauncherDelegateActivity

SET MY_DATETIME=%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%%TIME:~0,2%%TIME:~3,2%_%TIME:~6,2%
echo %MY_DATETIME%
SET LOG_PREFIX=%APP_NAME%_%MY_DATETIME%

if “%1”==”” (set ADB_PREFIX=adb) else (set ADB_PREFIX=adb -s %1)
SET ADB_SHELL_CMD=%ADB_PREFIX% shell
SET ADB_LOGCAT_CMD=%ADB_PREFIX% logcat
SET ADB_PULL=%ADB_PREFIX% pull
SET ADB_SCREEN_RECORD=%ADB_SHELL_CMD% screenrecord
SET FILE_RECORD=/sdcard/demo.mp4

for /L %%n in (1,1,%REPEAT_TIMES%) do (
echo “—–Times=” %%n
%ADB_LOGCAT_CMD% -c
%ADB_SHELL_CMD% am force-stop %APK_PKG_NAME%
echo “Start MMS application”
%ADB_SHELL_CMD% am start -n %APK_PKG_NAME%/%APK_ACTIVITY_LAUNCH%
echo “Wait 10 seconds”
timeout 10
start “” %ADB_SCREEN_RECORD% –time-limit 160 %FILE_RECORD%
echo “Start monkey test”
%ADB_SHELL_CMD% monkey -p %APK_PKG_NAME% –pct-touch 20 –pct-motion 20 –pct-nav 30 –pct-majornav 30 -s 12867 -v –throttle 3 5000>”Monkey_%LOG_PREFIX%_%%n.txt”
%ADB_LOGCAT_CMD% -d>”Logcat_%LOG_PREFIX%_%%n.txt”
%ADB_SHELL_CMD% busybox free -m >”MemoryUsage_%LOG_PREFIX%_%%n.txt”
%ADB_SHELL_CMD% dumpsys meminfo %APK_PKG_NAME% >”MemoryUsageApp_%LOG_PREFIX%_%%n.txt”
echo “Wait 160 seconds”
timeout 160
%ADB_PULL% %FILE_RECORD% “./Record_%LOG_PREFIX%_%%n.mp4”
%ADB_SHELL_CMD% rm %FILE_RECORD%
)

Pass UDID as first parameter if you have connected more than one devices.
Commands:
1. clear logs: adb logcat -c
2. Force stop the app: adb shell am force-stop < package name >
3. Start the app: adb shell am start -n < package name >/< activity name >
4. Start record the device screen for 180 seconds. (maximum is 180).
adb shell screenrecord –timelimit 180 < file record in device >
5. Execute monkey command and send output to a txt file.
adb shell monkey -p < package name > –pct-touch 20 –pct-motion 20 –pct-nav 30 –pct-majornav 30 -s 12867 -v –throttle 3 5000>Monkey_%LOG_PREFIX%_%%n.txt
6. Save log to a txt file for debugging: adb logcat > logcat.txt
7. Get memory information and save to txt file for debugging:
adb shell busybox free -m
adb shell dumpsys meminfo < package name > >MemoryUsageApp.txt
8. Pull file from device to the computer.
adb pull /sdcard/demo.mp4 < local file name >
9. Delete record file: adb shell rm /sdcard/demo.mp4
10. DOS: Start a new window to execute the command. start “” adb shell … Because screen record process need to be executed parallel with monkey test, so start a new window to do screen record and continue monkey test in current windows.
11. DOS: Wait for some time. timeout 60.
12. After executed, search the monkey log, if there is any CRASH. Can take a look at record video and know the screen cause the crash and has related logs from logcat for the developer to do debug.