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 ...
随机推荐
- MySQL常用语法命令及函数
#创建数据库# create database 数据库名; #查看数据库# show databases; #选择数据库# use 数据库名; #删除数据库# drop database 数据库名; ...
- 崔庆才Python3网络爬虫开发实战电子版书籍分享
资料下载地址: 链接:https://pan.baidu.com/s/1WV-_XHZvYIedsC1GJ1hOtw 提取码:4o94 <崔庆才Python3网络爬虫开发实战>高清中文版P ...
- eXosip2 编译安装
eXosip2-3.6.0 编译安装 刚开始我使用了 下面文章介绍里版本 我以为不支持tcp 其实是因为我服务端的端口 没有写对. https://www.cnblogs.com/elisha-bl ...
- Python2.7.13下载安装全过程(Windows版)
前提: 我下载的Python是windows版本的,演示过程是在win10 64位操作系统上安装的. 1.下载 进入官网https://www.python.org/,找到Dowdloads,根 ...
- AS添加依赖报错Unable to merge dex
AS添加依赖报错Unable to merge dex 最近在给项目添加依赖的时候,要给项目导入Bmob的SDK,参照Bmob的官方文档,可以直接在app的build.gradle文件中添加 //Bm ...
- Delphi下 Winsock 函数
用于初始化Winsock[声明]int WSAStarup(WORD wVersionRequested,LPWSADATA lpWSAData);[参数]wVersionRequested - 要求 ...
- poj1721
题解: 直接暴力循环节 然后再做几次 代码: #include<cstdio> #include<cstring> #include<algorithm> #inc ...
- 简单gulp.js
引入相对应的文件 let gulp = require("gulp"); let inject = require("gulp-inject"); let cl ...
- python简单爬虫 用lxml库解析数据
目标:爬取湖南大学2018年本科招生章程 url:http://admi.hnu.edu.cn/info/1026/2993.htm 页面部分图片: 使用工具: Python3.7 火狐浏览器 PyC ...
- python-原始字符串,长字符串
一 长字符串 在python中要表示跨行多行的字符串,可以使用较为简单粗暴的表达-----三引号.例如: str = ”’那时我们有梦, 关于文学, 关于爱情, 关于穿越世界的旅行. 如今我们深夜饮 ...