資源簡介
用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個文件信息
評論
共有 條評論