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 ...
随机推荐
- 双目深度估计传统算法流程及OpenCV的编译注意事项
起因: 1. 双目立体视觉中双目深度估计是非常重要且基础的部分,而传统的立体视觉的算法基本上都在opencv中有相对优秀的实现.同时考虑了性能和效率.因此,学习使用opencv接口是非常重要的. 2. ...
- day 06 编码and知识点总结
1.day 05 内容回顾 dict:dic = {'name':'alex'} 增:dic['age']=21#存在就覆盖 dic.setdefault(),没有就增加 删除: pop()按照key ...
- sys 模块的应用
1.常见的sys模块的应用: 1.在解释器启动后, argv 列表包含了传递给脚本的所有参数, 列表的第一个元素为脚本自身的名称 argv(命令行参数个数) #!/usr/bin/env python ...
- mybatis的配置与使用
mybatis的配置与使用 一.全局配置文件配置 properties标签 Properties标签可以用来加载配置文件.例如,我们可以将数据库的连接信息放入到一个配置文件(db.properties ...
- jQuery.support属性
jQuery.support 属性包含表示不同浏览器特性或漏洞的属性集. 此属性主要用于 jQuery 的内部使用 jQuery.support主要包括以下测试: boxModel: 如果这个页面和浏 ...
- S2T40,第四章,简答5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- ES6中var/let/const的区别
let的含义及let与var的区别: let 声明的变量只在它所在的代码块有效: 如下: for (let i = 0; i < 10; i++) { console.log(i); } con ...
- 字符串的顺序倒置。(Reverse)
实际遇到的问题:在串口获取码表数据的时候,有的码表传到电脑上的数字顺序是颠倒的,即:123.45,会显示为54.321.需要重新处理数据.方法很多,也不难实现,现在列举其中5个. public str ...
- eclipse中添加jstl标签支持(引入头)
https://blog.csdn.net/wangyuxuan_java/article/details/8580318
- [linux-脚本]shebang(shabang #!)
使用Linux或者unix系统的人们对#!这个符号都不陌生,但要说出个具体的所以然来,很多人估计还真不行,我们有必要就此整理一下.Shebang这个符号通常在Unix系统的脚本中第一行开头中写到,它指 ...