当前位置: 代码迷 >> 综合 >> monkey+python2.7,暂时不完善
  详细解决方案

monkey+python2.7,暂时不完善

热度:49   发布时间:2023-11-18 06:21:12.0

公司正在开发一款app,本着练手的原则,不放过每一次练习的机会。monkey+python2.7,简单的写了一下,基本可以,后续日志方面的东西还没整好。

#_*_coding=utf-8 _*_
#__author__ = 'Administrator'import os
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
import subprocess
import redef emaile(i):#构造纯文本邮件内容body = MIMEText('新近我寂寞浓烈如酒,夕阳下多姿的垂柳,亦让人不知其是长袖善舞还是骚在其骨...','plain','utf-8')msg =MIMEMultipart()#发件人邮箱地址sender = '809647468@qq.com'user = '809647468'password = 'zlmjeoeivdqfbecj'#smtp服务器地址smtpserver = 'smtp.qq.com'#接收者邮箱地址receiver = "809647468@qq.com"msg['from']=sendermsg['to']=receiversubject = 'chubby superman salutes you'msg['subject']=Header(subject,'utf-8')part =MIMEBase('application','octet-stream')txt = r'c:\test%d.txt'%ipart.set_payload(open(txt,'rb').read())Encoders.encode_base64(part)part.add_header('Content-Disposition', 'attachment; filename="test%d.txt"'%i)msg.attach(part)smtp = smtplib.SMTP()smtp.connect(smtpserver,25)smtp.login(user,password)smtp.sendmail(sender,receiver,msg.as_string())smtp.quit()open(txt,'rb').close()print('ahahah')os.system('adb kill-server')
os.system('taskkill /IM cmd.exe /F')
for i in range(20):a = 'taskkill /IM adb.exe /F&adb logcat *:e > c:\\test%d.txt&adb shell monkey -p com.health3722.pipicalculator --pct-touch 45 --pct-motion 45 ' \'--pct-trackball 0 --pct-appswitch 10 --pct-anyevent 0 --pct-nav 0 --pct-majornav 0 --pct-syskeys 0 -s 2 -v-v-v 100&taskkill /IM cmd.exe /F'%imonkey = 'adb shell monkey -s %s -p com.health3722.pipicalculator --pct-touch 35' \' --pct-syskeys 30 --pct-appswitch 35 --hprof --throttle 100 -v -v -v 10000 logcat *:e > c:\\test%s.txt'%(i,i)os.system(monkey)fp = file("c:\\test%i.txt"%i,'r')#count = 0print(i)for s in fp.readlines():li = re.findall('CrashManager',s)li1= re.findall('crash',s)if len(li)>0 or len(li1)>0:emaile(i)fp.close()