一. wxPython制作跑monkey工具python文件源代码内容Run Monkey.py如下:

#!/usr/bin/env python

import wx
import os
import sys
import time from threading import Thread #执行adb命令函数
#使用到的线程:RunMonkeyThread(),KillMonkeyThread(),ExportLogThread()
def excuOrder(orderName):
c = os.system(orderName)
print(c)
return c #将指定内容写入指定文件(写入monkey日志报错信息)
#使用到的函数:findException()
def writeFile(FileName, content):
FName = open(FileName, 'a')
FName.write(content)
FName.close() #查找指定文件里指定字符串的个数,并输出字符串所在行的内容
#使用到的线程:ExportLogThread()
def findException(tfile,sstr):
try:
lines=open(tfile,'r').readlines()
flen=len(lines)-1
acount = 0
fileException = "%s_%s" % (tfile,sstr)
tfileException = "%s.txt" % fileException writeFile(tfileException,"%s keywords:\n" % fileException)
for i in range(flen):
if sstr in lines[i]:
lineException = '\t%s\n'% lines[i] writeFile(tfileException,lineException)
acount+= 1 writeFile(tfileException,"%s frequency:%s" % (fileException,acount))
print('Please check Exception keywords in the "%s"\n' % tfileException)
except Exception as e:
print(e) class RunMonkeyThread(Thread): def __init__(self):
#线程实例化是立即启动
Thread.__init__(self)
self.logNameST = logNameST
self.start() def run(self):
print("Start running monkey ...\n")
self.packageName=packageText.GetValue()
self.MonkeyTime=MTText.GetValue()
self.MonkeyCount=MCText.GetValue()
self.strTime = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
self.logName = '%s_%s_monkey.log'%(self.packageName,self.strTime)
open(r"logname.txt",'w').write(self.logName)
self.logNameST.SetLabel("%s" % self.logName) self.orderName1='adb shell "monkey -p %s --throttle %s --ignore-crashes --monitor-native-crashes \
--ignore-security-exceptions --ignore-timeouts --ignore-native-crashes --pct-syskeys\
0 --pct-nav 20 --pct-majornav 20 --pct-touch 40 --pct-appswitch 10 -v -v -v %s\
> /sdcard/%s&" '% (self.packageName,self.MonkeyTime,self.MonkeyCount,self.logName)
excuOrder(self.orderName1) print("monkey finished.\n") class KillMonkeyThread(Thread): def __init__(self):
#线程实例化时立即启动
Thread.__init__(self)
self.start() def run(self):
#杀死进程的两种命令
#1. ps|grep monkey |awk '{print $2}' |xargs kill -9
#2. PID=`ps |grep monkey|awk '{print $2}'`;kill -9 $PID;
self.orderName2 = 'adb shell "ps|grep monkey |awk \'{print $2}\' |xargs kill -9"'
excuOrder(self.orderName2)
time.sleep(2)
print ("Kill monkey success!") class ExportLogThread(Thread): def __init__(self):
#线程实例化时立即启动
Thread.__init__(self)
self.start() def run(self):
self.logo = os.path.isfile('logname.txt')
self.LogNameList = []
if(self.logo):
self.Logname_file = open('logname.txt','r')
self.Lognames = self.Logname_file.readlines()
self.Logname_file.close()
for self.Logname in self.Lognames:
self.LogNameList = self.Logname.split("_")
self.LogFileName = self.LogNameList[0] + "_" + self.LogNameList[1] self.orderName4 = "adb pull /sdcard/%s ./MonkeyLog_%s/%s" % (self.Logname,self.LogFileName,self.Logname)
excuOrder(self.orderName4) time.sleep(5)
print (u"Pull %s success!" % self.Logname)
findException("./MonkeyLog_%s/%s" % (self.LogFileName,self.Logname) ,"CRASH" )
findException("./MonkeyLog_%s/%s" % (self.LogFileName,self.Logname) ,"Exception") self.orderName5 = "adb pull /data/anr/traces.txt ./MonkeyLog_%s/traces.txt" % self.LogFileName
excuOrder(self.orderName5) print("Export Log Complete.")
else:
print ("logname.txt is not exist!") class InsertFrame(wx.Frame): def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,title="Run monkey",
pos=wx.DefaultPosition,
size=wx.DefaultSize,style=wx.DEFAULT_FRAME_STYLE,
name="frame") panel = wx.Panel(self,-1) #创建画板 #应用包名
PackageLabel = wx.StaticText(panel, -1, "package name:")
global packageText
packageText = wx.TextCtrl(panel, -1, "",
size=(260,-1))
packageText.SetInsertionPoint(0) #monkey事件之间的间隔时间(ms)
MTLabel = wx.StaticText(panel, -1, "Monkey time:")
global MTText
MTText = wx.TextCtrl(panel, -1, "",
size=(260,-1)) #monkey事件总次数
MCLabel = wx.StaticText(panel, -1, "Monkey count:")
global MCText
MCText = wx.TextCtrl(panel, -1, "",
size=(260,-1)) global button1
#点击按钮运行monkey
button1 = wx.Button(panel,label="Run Monkey") #将按钮添加到画板 #杀死monkey
button2 = wx.Button(panel,label="Kill Monkey") #将按钮添加到画板 #导出日志
button3 = wx.Button(panel,label="Export Log") #将按钮添加到画板 #日志名字:
MonkeyLogName = wx.StaticText(panel, -1, "Monkey logName:")
global logNameST
logNameST = wx.TextCtrl(panel,-1,"",
size=(260,-1)) #绑定按钮的单击事件
self.Bind(wx.EVT_BUTTON, self.runMonkey, button1)
self.Bind(wx.EVT_BUTTON, self.killMonkey, button2)
self.Bind(wx.EVT_BUTTON, self.exportLog, button3)
#绑定窗口的关闭事件
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([PackageLabel,packageText,MTLabel,MTText,MCLabel,MCText,MonkeyLogName,logNameST,button1,button2,button3])
panel.SetSizer(sizer) def runMonkey(self, event):
RunMonkeyThread() def killMonkey(self,event):
KillMonkeyThread() def exportLog(self,event):
ExportLogThread() def OnCloseMe(self, event):
self.Close(True) def OnCloseWindow(self,event):
self.Destroy() class App(wx.App): def __init__(self,redirect=True, filename=None):
wx.App.__init__(self,redirect,filename) def OnInit(self):
print("Program Startup:")
self.frame = InsertFrame(parent=None,id=-1) #创建框架
self.frame.Show()
self.SetTopWindow(self.frame)
print(sys.stderr) #输出到stderr
return True def OnExit(self):
print("Program running complete.")
return True if __name__=="__main__":
app = App(redirect=True) #1.文本重定向从这开始
app.MainLoop()

二. 将py脚本文件打包成可执行的exe文件命令:

pyinstaller -F -w -i 1.ico --version-file file_version_info.txt "Run Monkey.py"

ico图片生成:

将一般格式的图片(例如png、jpg)转换为ico图片网址:https://www.converticon.com/

版本信息文件内容file_version_info.txt如下:

# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0.
filevers=(2, 0, 0, 0),
prodvers=(2, 0, 0, 0),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x0,
# Contains a bitmask that specifies the Boolean attributes of the file.
flags=0x0,
# The operating system for which this file was designed.
# 0x4 - NT and there is no need to change it.
OS=0x4,
# The general type of file.
# 0x1 - the file is an application.
fileType=0x1,
# The function of the file.
# 0x0 - the function is not defined for this fileType
subtype=0x0,
# Creation date and time stamp.
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'080403a8',
[StringStruct(u'Comments', u'RunMonkey v2.0'),
StringStruct(u'CompanyName', u''),
StringStruct(u'FileDescription', u'RunMonkey Application'),
StringStruct(u'FileVersion', u'2.0.0.0'),
StringStruct(u'LegalCopyright', u''),
StringStruct(u'ProductName', u'RunMonkey'),
StringStruct(u'ProductVersion', u'2.0.0.0'),
StringStruct(u'SpecialBuild', u'')])
]),
VarFileInfo([VarStruct(u'Translation', [2052, 936])])
]
)

pyinstaller打包工具安装命令:pip install pyinstaller

pyinstaller打包工具安装完成后,查看安装版本号命令:pyinstaller --version

安装wxpython命令:pip install wxPython

wxPython制作跑monkey工具(python3)的更多相关文章

  1. wxPython制作跑monkey工具(python3)-带事件百分比显示界面

    一. wxPython制作跑monkey工具(python3)-带事件百分比显示界面  源代码 Run Monkey.py #!/usr/bin/env python import wx import ...

  2. wxPython制作跑monkey工具(python3)-带显示设备列表界面

    一. wxPython制作跑monkey工具(python3)-带显示设备列表界面  源代码 Run Monkey.py #!/usr/bin/env python import wx import ...

  3. python制作命令行工具——fire

    python制作命令行工具--fire 前言 本篇教程的目的是希望大家可以通读完此篇之后,可以使用python制作一款符合自己需求的linux工具. 本教程使用的是google开源的python第三方 ...

  4. 【转】monkey工具简介

    原文地址:http://www.testwo.com/blog/6188   一.Monkey 简介 Android的SDK 里面,Monkey的tools是一个命令行工具,当连接Android设备时 ...

  5. Monkey工具之fastbot-iOS实践

    Monkey工具之fastbot-iOS实践 背景 目前移动端App上线后 crash 率比较高, 尤其在iOS端.我们需要一款Monkey工具测试App的稳定性,更早的发现crash问题并修复. 去 ...

  6. Monkey工具使用详解

    上节中介绍了Monkey工具使用环境的搭建,传送门..本节我将详细介绍Monkey工具的使用. 一.Monkey测试简介 Monkey测试是Android平台自动化的一种手段,通过Monkey程序模拟 ...

  7. Android APP压力测试(一)之Monkey工具介绍

    Android APP压力测试(一) 之Monkey工具介绍 前言 本文主要介绍Monkey工具.Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动. ...

  8. Android自动化压力测试图解教程——Monkey工具

    [置顶] Android自动化压力测试图解教程--Monkey工具 标签: 测试androidprofiling工具测试工具文档 2012-04-01 10:16 38185人阅读 评论(10) 收藏 ...

  9. Android压力测试快速入门教程(图解)——Monkey工具

    文章目录: 一.Monkey简介 二.Monkey的基本用法 三.Monkey测试示例图解 四.Monkey命令参数介绍 五.Monkey log分析 一.Monkey简介 Monkey:Androi ...

随机推荐

  1. INTRODUCE OF REPRESENTATIVE CPG-CONTROLLED ROBOTS

    仿生机器人研究是非常有意思的领域,它不仅从自然界中获取灵感,它也为一些生物的研究提供一个手段和基础,正如下图中所展示的.不论人工智能发展的如何迅速,机械结构始终做为着一个承载的平台,其重要性不可忽略. ...

  2. [luogu P3391] 文艺平衡树

    [luogu P3391] 文艺平衡树 题目背景 这是一道经典的Splay模板题——文艺平衡树. 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区 ...

  3. printf()、sprintf()、vprintf()、vsprintf()(转)

    转自http://sumsung753.blog.163.com/blog/static/14636450120112151092934/ 一.printf() printf()函数优点在于可以格式化 ...

  4. EVE-NG简单入门介绍

    此篇文章简单的介绍下模拟器EVE-NG的使用,具体包括Dynamips设备导入与运行,IOL设备的导入与运行,QEMU设备的导入与运行,客户端软件的安装,物理网络与虚拟网络的结合等. 一.导入镜像 D ...

  5. oracle数据库自学笔记(持续更新中……)

    以前的项目都是使用mysql数据库开发的,如今进了新的公司,开始接触到了Oracle数据库,而自己以前没有接触过,就自己挤时间来学习一下. 一.关系型数据库的概念 关系型数据理论由E.F.Codd博士 ...

  6. Android向通讯录添加联系人的一般方法

    Android向通讯录添加联系人的一般方法 以一个简单的例子加以说明,记得需要相应的权限: 测试代码,关键的内容就在add函数里面. package zhangphil.demo; import an ...

  7. R语言求根

    求根是数值计算的一个基本问题,一般采用的都是迭代算法求解,主要有不动点迭代法.牛顿-拉富生算法.割线法和二分法. 不动点迭代法 所谓的不动点是指x=f(x)的那些点,而所谓的不懂点迭代法是指将原方程化 ...

  8. spring cloud + spring boot + springmvc+mybatis分布式微服务云架构

    做一个微服务架构需要的技术整理: View: H5.Vue.js.Spring Tag.React.angularJs Spring Boot/Spring Cloud:Zuul.Ribbon.Fei ...

  9. Can peel peel solve pesticide problem

    Can peel peel solve pesticide problem? Middle peasants medicinal modern agriculture more and more, t ...

  10. SharePoint Framework 向web部件中添加外部库

    博客地址:http://blog.csdn.net/FoxDave 在进行开发的时候,你很可能会想要引用一些公开的JavaScript库到你的项目中,本文将会介绍如何打包和共享这些库. 打包脚本 默认 ...