python_adb 图形界面获取app测试数据,并展示部分测试报告v1.0版本(开源)

本文涉及的产品
阿里云百炼推荐规格 ADB PostgreSQL,4核16GB 100GB 1个月
简介: 笔记

  想到平时想用adb 我就忍不住去翻开笔记,脑子记不住,不好使,不知道大家有没有这个想法呢,不管你有没有,反正我有了,ttm,太烦人了,于是乎,我就开始给自己写个需求文档,

这就是我写的,产品需求,合理不,管他合不合理,我看着能舒服就可以,

1.png

其实做出来的真实的效果图差很远,待会会给你们展示的,这里我要说的是电量和帧率展示这个版本没有坐进来,没有考虑pass值不存在的情况,因为有些APP或许没有,

既然有了需求,那么开始写代码吧。我选择python3.6.1 (备注:这里不支持python2.7)

下面来展示下代码,先看获取值的代码

import os,time,platform,time
def starttime_app(packagename,packagenameactivicy):#启动耗时
    cmd='adb shell am start -W -n %s'%packagenameactivicy
    me=os.popen(cmd).read().split('\n')[-7].split(':')#获取启动时间
    cmd2='adb shell am force-stop %s'%packagename
    os.system(cmd2)
    return me
def makesure_system():
    if platform.system =='Windows':
        find='findstr'
    else:
        find='grep'
def liulang(packagename):
    cmd='adb shell cat /data/system/packages.list | findstr %s'%packagename
    cm=os.popen(cmd).read().split()[1]
    cmd1='adb shell cat /proc/net/xt_qtaguid/stats | findstr %s'%cm
    me1_shou=os.popen(cmd1).read().split()[5]#接受
    me2_shou=os.popen(cmd1).read().split()[7]#上传
    cmd2='adb shell cat /proc/net/xt_qtaguid/stats | findstr %s'%cm
    me1_xia=os.popen(cmd1).read().split()[5]#接受
    me2_xia=os.popen(cmd1).read().split()[7]#上传
    liulang_sum_1=(int(me1_shou)+int(me2_shou))#过程产生流量计算为执行后的流量-执行前的流量,
    liulang_sum_xia=(int(me1_xia)+int(me2_xia))
    liulang_sum=int(liulang_sum_xia)-int(liulang_sum_1)
    me1=int(me1_xia)-int(me1_shou)
    me2=int(me2_xia)-int(me2_shou)
    return me1 ,me2,liulang_sum
def caijicpu(packagename):#这里采集的cpu时候可以是执行操作采集 就是-n  -d  刷新间隔
    cpu='adb shell top -n 1| findstr %s'%packagename
    re_cpu=os.popen(cpu).read().split()[2]
    return re_cpu
def getnencun(packagename):#Total 的 PSS 信息内存
    cpu='adb shell  dumpsys  meminfo %s'%packagename
    re_cpu=os.popen(cpu).read().split()[118]
    return re_cpu
def huoqufps(packagename):
    cmd ='adb shell dumpsys gfxinfo packagename '#获取fps
def adb_monkey(packagename,s_num,throttle,pct_touch,pct_motion,pct_trackball,pct_nav,pct_syskeys,pct_appswitch,num,logfilepath):
    cmden='adb shell monkey -p %s -s %s --throttle %s --pct-touch %s --pct-motion %s  --pct-trackball  %s  --pct-trackball %s  --pct-syskeys  %s  --pct-appswitch  %s --ignore-crashes --ignore-timeouts --monitor-native-crashes  -v -v -v %s >%s'%(packagename,s_num,throttle,pct_touch,pct_motion,pct_trackball,pct_nav,pct_syskeys,pct_appswitch,num,logfilepath)
    os.popen(cmden)
def huoqushebeizhuangtai():
    cmd1='adb get-state'
    devices_status=os.popen(cmd1).read().split()[0]
    return devices_status
if __name__ == '__main__':
    print(getnencun('com.tencent.mobileqq'))

目前所有的数据的采集全部使用adb 来采集的,采集后呢,我这里使用了zuilow的分割办法来取值。


from ab_python import starttime_app,adb_monkey,huoqushebeizhuangtai,caijicpu,liulang,getnencun
import tkinter ,threading
from time import sleep
from tkinter import messagebox,ttk
from tkinter import *
from py_excel import qidongceshi,getcpu
def qidongapp():
    start_tim=[]
    cishu=[]
    status_shebei=huoqushebeizhuangtai()
    if status_shebei =='device':
        packname=baoming_t.get('0.0',END)
        acti=activ_t.get('0.0',END)
        cish=cishu_ac.get()
        if len(acti)<=1 or len(packname)<=1:
            messagebox.showinfo('提醒','包命或者包名activity不能为空')
        else:
            if len(cish)<=1:
                messagebox.showinfo('提醒','次数不能为空')
            else:
                i=0
                e1['state']= 'normal'
                e1.delete(1.0,tkinter.END)
                sum=0
                for i in range(int(cish)):
                    start_time=starttime_app(packagename=packname,packagenameactivicy=acti)
                    start_tim.append(int(start_time[1]))
                    cishu.append(i)
                    if start_time is None:
                        messagebox.showwarning('警告','请检查您输入的包或者包的启动activity')
                        break
                    text='第%s次启动时间:%s'%(i+1,start_time[1])
                    sum+=int(start_time[1])
                    e1['state']= 'normal'
                    e1.insert(tkinter.END,text)
                    e1.insert(tkinter.END,'\n')
                    e1.see(END)
                    btn_start['state']= 'disabled'
                e1.insert(tkinter.END,('平均用时:%s'%(sum/int(cish))))
                qidongceshi(cishu=cishu,start=start_tim)
                messagebox.showinfo('提示','测试报告已经生成,请到当前目录查看')
                e1['state']= 'disabled'
                btn_start['state']= 'normal'
                messagebox.showinfo('通知','测试已经完成')
    else:
        messagebox.showerror('警告','设备连接异常')
def monkey_app():
    status_shebei=huoqushebeizhuangtai()
    if status_shebei =='device':
        try:
            packname=baoming_t1.get('0.0',END).split()[0]
            zhongzi=zhongzi_t.get('0.0',END).split()[0]
            time=time_t.get().split()[0]
            touch=touch_t.get('0.0',END).split()[0]
            huadong=huadong_t.get('0.0',END).split()[0]
            guiji=guiji_t.get('0.0',END).split()[0]
            xitong=xitong_t.get('0.0',END).split()[0]
            acti=acti_t.get('0.0',END).split()[0]
            event=event_t.get('0.0',END).split()[0]
            log=log_t.get('0.0',END).split()[0]
            danghang=danghang_t.get('0.0',END).split()[0]
            if len(packname)<=5:
                messagebox.showwarning('提醒','请正确填写包名')
            if int(touch)+int(huadong)+int(guiji)+int(danghang)+int(xitong)+int(acti) >100:
                messagebox.showerror('提醒','您输入的所有的事件的比例和不能超过100%')
            # btn_monkey['state']= 'disabled'
            adb_monkey(packagename=packname,s_num=zhongzi,throttle=time,pct_touch=touch,pct_motion=huadong,pct_trackball=guiji,pct_nav=danghang,pct_syskeys=xitong,pct_appswitch=acti,num=event,logfilepath=log)
            # messagebox.showinfo('通知',('测试完毕,日志存放:%s'%log))
            # btn_monkey['state']= 'normal'
        except :
            messagebox.showwarning('警告','必须填写monkey相关数据')
    else:
        messagebox.showwarning('警告','设备连接异常 请重新连接设备!')
def cpu_app():
    status_shebei=huoqushebeizhuangtai()
    if status_shebei =='device':
        xingneng_bao=xingneng_baoming.get('0.0',END).split()[0]
        xing=xing_t.get()
        if len(xingneng_bao)<=5:
            messagebox.showwarning('警告','请检查您的包名')
        cishu_list=[]
        cpu_list=[]
        rescv_list=[]
        send_list=[]
        total_list=[]
        pass_list=[]
        i=0
        for i in range(int(xing)):
            nen_cun=getnencun(xingneng_bao)
            rescv,send,liulang_sum=liulang(xingneng_bao)
            cpu_caiji=caijicpu(xingneng_bao)
            neicun_t['state']= 'normal'
            pass_list.append(int(nen_cun))
            neicun_t.insert(tkinter.END,('Pass值:%s'%nen_cun))
            neicun_t.insert(tkinter.END,'\n')
            neicun_t.see(END)
            neicun_t['state']= 'disabled'
            cpu_t['state']= 'normal'
            cpu_list.append(int(cpu_caiji.split('%')[0]))
            cpu_t.insert(tkinter.END,('CPU占有率:%s'%cpu_caiji))
            cpu_t.insert(tkinter.END,'\n')
            cpu_t.see(END)
            cpu_t['state']= 'disabled'
            liulang_t['state']= 'normal'
            total_list.append(int(liulang_sum))
            rescv_list.append(int(rescv))
            send_list.append(int(send))
            liulang_t.insert(tkinter.END,('总流量:%sk,上传流量:%sk,下载流量:%sk'%(liulang_sum,rescv,send)))
            liulang_t.insert(tkinter.END,'\n')
            liulang_t.see(END)
            liulang_t['state']= 'disabled'
            xingneng_btn['state']= 'disabled'
            i+=1
            cishu_list.append(int(i))
        getcpu(cishu=cishu_list,start_cpu=cpu_list,recv_list=rescv_list,send_list=send_list,total_list=total_list,Pass_list=pass_list)
        xingneng_btn['state']= 'normal'
        messagebox.showinfo('提醒','测试完毕,测试报告已经生成!')
    else:
        messagebox.showwarning('警告','设备连接异常 请重新连接设备!')
def teread():
    for i in range(1):
        t=threading.Thread(target=cpu_app,args=())
        t.start()
def teread_start():
    for i in range(1):
        t=threading.Thread(target=qidongapp,args=())
        t.start()
if __name__ == '__main__':
    try:
        status_shebei=huoqushebeizhuangtai()
        if status_shebei =='device':
            root=tkinter.Tk()
            root.title('雷子的安卓adb小工具')
            # root.geometry("1000x900")
            # root.resizable(width=False, height=False)
            tkinter.Label(root,text='性能参数展示',fg='red',font=("黑体", 15, "bold"),).grid(row=0,column=3)
            cpu_t=tkinter.Text(root,height=5,width=30)
            cpu_t.grid(row=1,column=2)
            liulang_t=tkinter.Text(root,height=5,width=40)
            liulang_t.grid(row=1,column=4)
            liulang_t.see(END)
            neicun_t=tkinter.Text(root,height=5,width=30)
            neicun_t.grid(row=3,column=2)
            neicun_t.see(END)
            suji_ev=[50,100,150,200,300]#这里还原可以增加可以选择的次数
            xing_t=ttk.Combobox(root,values=suji_ev,width=5)
            xing_t.current(0)
            xing_t.grid(row=1,column=6)
            tkinter.Label(root,text='cpu').grid(row=2,column=2)
            tkinter.Label(root,text='参数次数').grid(row=1,column=5)
            tkinter.Label(root,text='流量').grid(row=2,column=4)
            tkinter.Label(root,text='内存').grid(row=6,column=2)
            tkinter.Label(root,text='包名:').grid(row=7,column=1)
            xingneng_baoming=tkinter.Text(root,height=1,width=30)
            xingneng_baoming.grid(row=7,column=2)
            xingneng_btn=tkinter.Button(root,text='开始测试',font=("黑体", 15, "bold"),command=teread)
            xingneng_btn.grid(row=7,column=3)
            tkinter.Label(root,text='启动时间测试',fg='red',height=2,font=("黑体", 15, "bold")).grid(row=8,column=3)
            tkinter.Label(root,text='测试包名').grid(row=9,column=1)
            baoming_t=tkinter.Text(root,height=1,width=30)
            baoming_t.grid(row=9,column=2)
            tkinter.Label(root,text='测试包Activity').grid(row=9,column=3)
            activ_t=tkinter.Text(root,height=1,width=30)
            activ_t.grid(row=9,column=4)
            tkinter.Label(root,text='测试次数').grid(row=9,column=5)
            num=[10,20,30,50,100]
            cishu_ac=ttk.Combobox(root,values=num,state='readonly',width=5)
            cishu_ac.current(0)
            cishu_ac.grid(row=9,column=6)
            tkinter.Label(root,text='启动时间展示').grid(row=10,column=1)
            e1 = tkinter.Text(root,width=30,height=10, state="disabled")
            e1.grid(row=10,column=2,padx=20,pady=30)
            btn_start=tkinter.Button(root,text='测试',font=("黑体", 15, "bold"),command=teread_start)
            btn_start.grid(row=10,column=3)
            tkinter.Label(root,text='Monkey 测试',fg='red',font=("黑体", 15, "bold")).grid(row=11,column=3)
            tkinter.Label(root,text='测试包名:').grid(row=12,column=1)
            baoming_t1=tkinter.Text(root,height=1,width=30)
            baoming_t1.insert('0.0',0)
            baoming_t1.grid(row=12,column=2)
            tkinter.Label(root,text='随机种子数:').grid(row=12,column=3)
            zhongzi_t=tkinter.Text(root,height=1,width=30)
            zhongzi_t.grid(row=12,column=4)
            zhongzi_t.insert('0.0',0)
            tkinter.Label(root,text='时间间隔:').grid(row=12,column=5)
            suji_event=[500,1000,1500,2000,3000]
            time_t=ttk.Combobox(root,values=suji_event,width=5)
            time_t.current(0)
            time_t.grid(row=12,column=6)
            tkinter.Label(root,text='导航事件百分比:').grid(row=13,column=1)
            danghang_t=tkinter.Text(root,height=1,width=30)
            danghang_t.insert('0.0',0)
            danghang_t.grid(row=13,column=2)
            tkinter.Label(root,text='触摸事件百分比:').grid(row=13,column=3)
            touch_t=tkinter.Text(root,height=1,width=30)
            touch_t.grid(row=13,column=4)
            touch_t.insert('0.0',0)
            tkinter.Label(root,text='滑动事件百分比:').grid(row=14,column=1)
            huadong_t=tkinter.Text(root,height=1,width=30)
            huadong_t.grid(row=14,column=2)
            huadong_t.insert('0.0',0)
            tkinter.Label(root,text='轨迹球事件百分比:').grid(row=14,column=3)
            guiji_t=tkinter.Text(root,height=1,width=30)
            guiji_t.grid(row=14,column=4)
            guiji_t.insert('0.0',0)
            tkinter.Label(root,text='系统按键百分比:').grid(row=15,column=1)
            xitong_t=tkinter.Text(root,height=1,width=30)
            xitong_t.grid(row=15,column=2)
            xitong_t.insert('0.0',0)
            tkinter.Label(root,text='activity之间的切换百分比:').grid(row=15,column=3)
            acti_t=tkinter.Text(root,height=1,width=30)
            acti_t.grid(row=15,column=4)
            acti_t.insert('0.0',0)
            tkinter.Label(root,text='事件量:').grid(row=16,column=1)
            event_t=tkinter.Text(root,height=1,width=30)
            event_t.insert('0.0',0)
            event_t.grid(row=16,column=2)
            tkinter.Label(root,text='日志存放路径:').grid(row=16,column=3)
            log_t=tkinter.Text(root,height=1,width=30)
            log_t.grid(row=16,column=4)
            log_t.insert('0.0','F:\\monekey.txt')
            btn_monkey=tkinter.Button(root,text='启动Monkey测试',font=("黑体", 15, "bold"),command=monkey_app)
            btn_monkey.grid(row=17,column=3)
            root.mainloop()
        else:
            print(status_shebei)
            print('设备未连接或者连接异常')
    except Exception as e:
        print(e)
        print('请检查您是否连接设备')

图形界面呢,我使用python原生的tkinter,这里值得是问我,你开线程,开一个开多个行吗,没有问题,可以去修改试试就知道,下面的关于Excel报告的Excel我就不展示了,xlsxwriter库,可以去看看官方很多例子。

展示效果图。

5.png

 

展示测试报告

6.png7.png8.png


 


 

 

相关实践学习
阿里云百炼xAnalyticDB PostgreSQL构建AIGC应用
通过该实验体验在阿里云百炼中构建企业专属知识库构建及应用全流程。同时体验使用ADB-PG向量检索引擎提供专属安全存储,保障企业数据隐私安全。
AnalyticDB PostgreSQL 企业智能数据中台:一站式管理数据服务资产
企业在数据仓库之上可构建丰富的数据服务用以支持数据应用及业务场景;ADB PG推出全新企业智能数据平台,用以帮助用户一站式的管理企业数据服务资产,包括创建, 管理,探索, 监控等; 助力企业在现有平台之上快速构建起数据服务资产体系
相关文章
|
11天前
|
机器学习/深度学习 存储 人工智能
MNN-LLM App:在手机上离线运行大模型,阿里巴巴开源基于 MNN-LLM 框架开发的手机 AI 助手应用
MNN-LLM App 是阿里巴巴基于 MNN-LLM 框架开发的 Android 应用,支持多模态交互、多种主流模型选择、离线运行及性能优化。
884 14
MNN-LLM App:在手机上离线运行大模型,阿里巴巴开源基于 MNN-LLM 框架开发的手机 AI 助手应用
|
6天前
|
数据采集 数据安全/隐私保护 Python
从零开始:用Python爬取网站的汽车品牌和价格数据
在现代化办公室中,工程师小李和产品经理小张讨论如何获取懂车帝网站的汽车品牌和价格数据。小李提出使用Python编写爬虫,并通过亿牛云爬虫代理避免被封禁。代码实现包括设置代理、请求头、解析网页内容、多线程爬取等步骤,确保高效且稳定地抓取数据。小张表示理解并准备按照指导操作。
从零开始:用Python爬取网站的汽车品牌和价格数据
|
1月前
|
分布式计算 Shell MaxCompute
odps测试表及大量数据构建测试
odps测试表及大量数据构建测试
|
1天前
|
算法 Serverless 数据处理
从集思录可转债数据探秘:Python与C++实现的移动平均算法应用
本文探讨了如何利用移动平均算法分析集思录提供的可转债数据,帮助投资者把握价格趋势。通过Python和C++两种编程语言实现简单移动平均(SMA),展示了数据处理的具体方法。Python代码借助`pandas`库轻松计算5日SMA,而C++代码则通过高效的数据处理展示了SMA的计算过程。集思录平台提供了详尽且及时的可转债数据,助力投资者结合算法与社区讨论,做出更明智的投资决策。掌握这些工具和技术,有助于在复杂多变的金融市场中挖掘更多价值。
22 12
|
9天前
|
开发框架 缓存 搜索推荐
PiliPala:开源项目真香,B站用户狂喜!这个开源APP竟能自定义主题+去广告?PiliPala隐藏功能大揭秘
嗨,大家好,我是小华同学。PiliPala 是一个基于 Flutter 开发的 BiliBili 第三方客户端,提供流畅、个性化的使用体验。核心功能包括视频浏览与推荐、用户互动、丰富的播放设置、多维度搜索和个性化主题等。相比官方客户端,PiliPala 功能更丰富、性能更优、界面更美观。
60 14
|
22天前
|
人工智能 开发者 Python
Chainlit:一个开源的异步Python框架,快速构建生产级对话式 AI 应用
Chainlit 是一个开源的异步 Python 框架,帮助开发者在几分钟内构建可扩展的对话式 AI 或代理应用,支持多种工具和服务集成。
137 9
|
1月前
|
数据采集 Web App开发 数据可视化
Python用代理IP获取抖音电商达人主播数据
在当今数字化时代,电商直播成为重要的销售模式,抖音电商汇聚了众多达人主播。了解这些主播的数据对于品牌和商家至关重要。然而,直接从平台获取数据并非易事。本文介绍如何使用Python和代理IP高效抓取抖音电商达人主播的关键数据,包括主播昵称、ID、直播间链接、观看人数、点赞数和商品列表等。通过环境准备、代码实战及数据处理与可视化,最终实现定时任务自动化抓取,为企业决策提供有力支持。
|
2月前
|
开发框架 .NET Java
C#集合数据去重的5种方式及其性能对比测试分析
C#集合数据去重的5种方式及其性能对比测试分析
38 11
|
2月前
|
开发框架 .NET Java
C#集合数据去重的5种方式及其性能对比测试分析
C#集合数据去重的5种方式及其性能对比测试分析
55 10
|
2月前
|
数据采集 Web App开发 监控
Python爬虫:爱奇艺榜单数据的实时监控
Python爬虫:爱奇艺榜单数据的实时监控

热门文章

最新文章

推荐镜像

更多