资源简介
用Python 编写的一个Monkey脚本例子

代码片段和文件信息
# -*- coding: utf-8 -*-
import time os
# execute times
execcount = 2
# execute interval (seconds)
execinterval = 1 * 5
monkeyclickcount = 1000
WORKSPACE = os.path.abspath(“.“)
def getWorkConfig():
f = open(“./.config“ “r“)
config = {“monkeyclickcount“: monkeyclickcount “execcount“: execcount}
try:
while True:
line = f.readline()
if line:
line = line.strip()
linesplit = line.split(“:“)
if linesplit.__sizeof__() > 1:
if linesplit[0] == ‘phone‘:
config[‘phone‘] = linesplit[1]
elif linesplit[0] == ‘monkeyclickcount‘:
config[“monkeyclickcount“] = linesplit[1]
elif linesplit[0] == ‘execcount‘:
config[“execcount“] = linesplit[1]
else:
break
finally:
f.close()
print “config : %s“ % config
return config
def installApk(config):
phoneAddr = config.get(“phone“)
print ‘Ready to start installing apk‘
if phoneAddr:
installPhoneApk = “adb -s %s install -r %s\\apk\\app-inland-debug.apk“ % (phoneAddr WORKSPACE)
os.popen(installPhoneApk)
print “install phone apk done“
def killTestApp():
forceStopApp = “adb -s %s shell am force-stop com.example.demo1“ % workConfig.get(‘phone‘)
os.popen(forceStopApp)
def fullmonkey(workconfig):
killTestApp()
monkeycmd = “adb -s %s shell monkey -p com.example.demo1 “ \
“--ignore-timeouts --ignore-crashes --kill-process-after-error “ \
“--pct-touch 35 --pct-syskeys 30 --pct-appswitch 35 --hprof “ \
“--throttle 100 -v -v -v %s“ \
% (workconfig.get(“phone“) workConfig.get(“monkeyclickcount“))
os.popen(monkeycmd)
def createBugreport():
print “create bugreport file“
bugreport = “adb -s %s shell bugreport > %s\\bugreport.txt“ % (workConfig.get(“phone“) WORKSPACE)
os.popen(bugreport)
print “create bugreport file done“
chkbugreport = “java -jar %s\\chkbugreport.jar %s\\bugreport.txt“ % (WORKSPACE WORKSPACE)
os.popen(chkbugreport)
workConfig = getWorkConfig()
installApk(workConfig)
forcount = int(workConfig.get(“execcount“))
for i in range(forcount):
print “execute monkey loop = %s“ % (i + 1)
fullmonkey(workConfig)
time.sleep(execinterval)
createBugreport()
print “Completion of the current round of testing“
raw_input(“Enter key to close“)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-04-06 10:49 monkey_test\
文件 62 2017-02-20 21:40 monkey_test\.config
目录 0 2017-04-06 11:06 __MACOSX\
目录 0 2017-04-06 11:06 __MACOSX\monkey_test\
文件 222 2017-02-20 21:40 __MACOSX\monkey_test\._.config
文件 6148 2017-04-06 10:51 monkey_test\.DS_Store
文件 120 2017-04-06 10:51 __MACOSX\monkey_test\._.DS_Store
目录 0 2017-02-20 22:23 monkey_test\.idea\
文件 238 2016-10-25 15:32 monkey_test\.idea\encodings.xm
目录 0 2017-04-06 11:06 __MACOSX\monkey_test\.idea\
文件 222 2016-10-25 15:32 __MACOSX\monkey_test\.idea\._encodings.xm
文件 687 2016-10-25 14:07 monkey_test\.idea\misc.xm
文件 222 2016-10-25 14:07 __MACOSX\monkey_test\.idea\._misc.xm
文件 268 2016-10-25 14:07 monkey_test\.idea\modules.xm
文件 222 2016-10-25 14:07 __MACOSX\monkey_test\.idea\._modules.xm
文件 398 2016-10-25 14:08 monkey_test\.idea\unti
文件 222 2016-10-25 14:08 __MACOSX\monkey_test\.idea\._unti
文件 39556 2017-02-20 22:23 monkey_test\.idea\workspace.xm
文件 222 2017-02-20 22:23 __MACOSX\monkey_test\.idea\._workspace.xm
文件 222 2017-02-20 22:23 __MACOSX\monkey_test\._.idea
目录 0 2017-02-20 21:37 monkey_test\apk\
文件 1295433 2017-02-13 21:25 monkey_test\apk\app-inland-debug.apk
目录 0 2017-04-06 11:06 __MACOSX\monkey_test\apk\
文件 222 2017-02-13 21:25 __MACOSX\monkey_test\apk\._app-inland-debug.apk
文件 222 2017-02-20 21:37 __MACOSX\monkey_test\._apk
文件 8292088 2017-02-20 21:45 monkey_test\bugreport.txt
文件 222 2017-02-20 21:45 __MACOSX\monkey_test\._bugreport.txt
目录 0 2017-02-20 21:43 monkey_test\bugreport_out\
目录 0 2017-02-20 21:45 monkey_test\bugreport_out\data\
文件 190 2017-02-20 21:42 monkey_test\bugreport_out\data\amchart_1002191352.png
目录 0 2017-04-06 11:06 __MACOSX\monkey_test\bugreport_out\
............此处省略1720个文件信息
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论