wxPython制作跑monkey工具(python3)
一. 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)的更多相关文章
- wxPython制作跑monkey工具(python3)-带事件百分比显示界面
一. wxPython制作跑monkey工具(python3)-带事件百分比显示界面 源代码 Run Monkey.py #!/usr/bin/env python import wx import ...
- wxPython制作跑monkey工具(python3)-带显示设备列表界面
一. wxPython制作跑monkey工具(python3)-带显示设备列表界面 源代码 Run Monkey.py #!/usr/bin/env python import wx import ...
- python制作命令行工具——fire
python制作命令行工具--fire 前言 本篇教程的目的是希望大家可以通读完此篇之后,可以使用python制作一款符合自己需求的linux工具. 本教程使用的是google开源的python第三方 ...
- 【转】monkey工具简介
原文地址:http://www.testwo.com/blog/6188 一.Monkey 简介 Android的SDK 里面,Monkey的tools是一个命令行工具,当连接Android设备时 ...
- Monkey工具之fastbot-iOS实践
Monkey工具之fastbot-iOS实践 背景 目前移动端App上线后 crash 率比较高, 尤其在iOS端.我们需要一款Monkey工具测试App的稳定性,更早的发现crash问题并修复. 去 ...
- Monkey工具使用详解
上节中介绍了Monkey工具使用环境的搭建,传送门..本节我将详细介绍Monkey工具的使用. 一.Monkey测试简介 Monkey测试是Android平台自动化的一种手段,通过Monkey程序模拟 ...
- Android APP压力测试(一)之Monkey工具介绍
Android APP压力测试(一) 之Monkey工具介绍 前言 本文主要介绍Monkey工具.Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动. ...
- Android自动化压力测试图解教程——Monkey工具
[置顶] Android自动化压力测试图解教程--Monkey工具 标签: 测试androidprofiling工具测试工具文档 2012-04-01 10:16 38185人阅读 评论(10) 收藏 ...
- Android压力测试快速入门教程(图解)——Monkey工具
文章目录: 一.Monkey简介 二.Monkey的基本用法 三.Monkey测试示例图解 四.Monkey命令参数介绍 五.Monkey log分析 一.Monkey简介 Monkey:Androi ...
随机推荐
- sass学习小记
错误 在sass命令行编译中遇到了一个错误: error E:/前端2/css揭秘/CSS-study/css揭秘/css揭秘.scss (Line 29: Invalid GBK character ...
- 【nowcoder】 4th T1 动态点分治
题目链接:https://www.nowcoder.com/acm/contest/175/A 题目名字吓死人 std: 我 太可啪了 一道简单的模拟题.虽然我把题意想错了. 按照题意模拟输出和继承. ...
- 解决Mac应用程序软件不出现在Launchpad里面的方法
新装了几个软件,可是打开Lauchpad之后却在里面找不到,真是烦人!然后尝试了以下方法: 1.重启电脑,没用: 2.尝试打开“应用程序(英文名称:Applications)”并找到安装的软件,然后直 ...
- 【转】使用iTextSharp在Asp.Net中操作PDF
使用iTextSharp在Asp.Net中操作PDF操作 使用iTextSharp在Asp.Net中操作PDF系列文章目录 实战 iTextSharp iTextSharp 合并多个PDF文件 C#生 ...
- maven 项目提示找不到javax.servlet.xxx问题解决
1.https://search.maven.org/search?q=g:javax.servlet%20AND%20a:javax.servlet-api&core=gav 2.下载3.1 ...
- Python_Mix*匿名函数,sorted,filter,map,递归函数,二分法查找
lambda匿名函数(函数名统一都叫lambda) 为了解决简单的需求而设计的一句话函数 语法: lambda 参数 返回值 n = lambda a,b: max(a,b) ret = n(9,4) ...
- JS的全局变量与局部变量及变量的提升
遇到全局变量与局部变量的时候总是出一些或多或少的问题,于是专门花时间去认真研究了一下全局变量与局部变量. 这是在网上看到的一个关于全局变量与局部变量的代码,看了下作者的解析,自己也进行了研究. < ...
- jenkins 关闭和重启的实现
jerkins自带的重启手段重启过程缓慢,在jenkins的操作过程中可使用以下操作: 关闭Jenkins 只需要在访问jenkins服务器的网址url地址后加上exit.例如我jenkins的地址h ...
- 21. Merge Two Sorted Lists★
题目内容:Merge two sorted linked lists and return it as a new list. The new list should be made by splic ...
- numpy数据集练习
#1. 安装scipy,numpy,sklearn包 import numpy as np #2. 从sklearn包自带的数据集中读出鸢尾花数据集data from sklearn.datasets ...