• App测试总脚本1.30.py


    # -*- coding: utf-8 -*-
    # @Time : 2019/8/2 16:23
    # @Author : Aluosen
    # @FileName: App测试总脚本1.20.py
    # @Software: PyCharm
    # @Cnblogs :https://www.cnblogs.com/Aluosen
    # @Software: PyCharm
    import os,csv
    class App():
    def __init__(self):
    self.Appchoose=0
    self.ThisTime=0
    self.apps=['微信','链家','宝骏','退出程序']
    self.Operations=['关闭App','App退到后台','查看启动时间','查看Cpu','获取进程号PID','查看进程流量','查看占用内存','查看电量','返回']
    def run(self):
    self.LaunchApp()
    self.OperationChoose()
    def LaunchApp(self):
    self.n=1
    print('-' * 64)
    print('APP名称:')
    for app in self.apps:
    print(f' {self.n}.{app}')
    self.n+=1
    App_choose = input('请选择您要开启的APP名称【1-4】:')
    if App_choose=='1':
    # global Appchoose
    print(' 正在开启微信……')
    content=os.popen('adb shell am start -W com.tencent.mm/.ui.LauncherUI')
    print(' 微信开启成功')
    self.Appchoose='com.tencent.mm'
    #链家
    elif App_choose=='2':
    print(' 正在开启链家……')
    content=os.popen('adb shell am start -W com.homelink.android/.SplashScreenActivity')
    print(' 链家开启成功')
    self.Appchoose ='com.homelink.android'
    #宝骏
    elif App_choose=='3':
    print(' 正在开启宝骏……')
    content=os.popen('adb shell am start -W com.tjd.Baojun/.Loading')
    print(' 宝骏开启成功')
    self.Appchoose ='com.tjd.Baojun'
    #退出程序
    elif App_choose == '4':
    print(' 正在退出程序')
    exit()
    else:
    print('您的输入有误,请重新输入')
    self.LaunchApp()
    print(' 请稍候……')
    # global ThisTime
    self.ThisTime=''.join([line.split()[1] for line in content.readlines() if 'ThisTime:' in line])

    def OperationChoose(self):
    self.n=1
    print('-' * 64)
    print('操作选择:')
    for Operation in self.Operations:
    print(f' {self.n}.{Operation}')
    self.n+=1
    Operation_choose = input('请选择您要进行的操作【1-9】')
    print('-' * 64)
    #关闭App
    if Operation_choose == '1':
    print(' 正在关闭App……')
    os.popen('adb shell am force-stop %s' % self.Appchoose)
    #程序转到后台
    elif Operation_choose == '2':
    print(' 正在退到后台……')
    os.popen('adb shell input keyevent 3')
    print(' 退到后台成功')
    self.OperationChoose()
    #查看启动时间
    elif Operation_choose=='3':
    print(' 启动时间(ms):',self.ThisTime)
    self.OperationChoose()
    #查看Cpu
    elif Operation_choose == '4':
    print(' 查看Cpu:')
    content = os.popen('adb shell dumpsys cpuinfo|findstr %s' % self.Appchoose)
    [print(line) for line in content.readlines() if '%s: '%self.Appchoose in line]
    self.OperationChoose()
    #获取进程号
    elif Operation_choose == '5':
    print(' 正在获取进程号Pid')
    content = os.popen('adb shell dumpsys cpuinfo|findstr %s' % self.Appchoose)
    print(' 进程号Pid:',''.join([line.split()[1].split('/')[0] for line in content.readlines() if '%s: ' % self.Appchoose in line]))
    self.OperationChoose()
    #获取进程流量
    elif Operation_choose == '6':
    print(' 查看进程流量:')
    content = os.popen('adb shell dumpsys cpuinfo|findstr %s' % self.Appchoose)
    pid = ''.join([line.split()[1].split('/')[0] for line in content.readlines() if '%s: ' % self.Appchoose in line])
    content = os.popen('adb shell cat /proc/%s/net/dev' % pid)
    line=''.join([line for line in content.readlines() if "eth" in line])
    Receiverbytes, Transmitbytes = line.split()[1], line.split()[9]
    Titlebytes = int(Receiverbytes) + int(Transmitbytes)
    print(" 接收字节数:", Receiverbytes)
    print(" 传输字节数:", Transmitbytes)
    print(" 总流量(byte):", Titlebytes, 'byte')
    print(" 总流量(Mb):", Titlebytes / 1024, 'Mb')
    self.OperationChoose()
    #获取进程占用内存
    elif Operation_choose == '7':
    print(' 进程占用内存:')
    content=os.popen('adb shell dumpsys meminfo %s'%self.Appchoose)
    print(' TOTAL:', ''.join([line.split()[1] for line in content.readlines() if 'TOTAL' in line]))
    self.OperationChoose()
    #获取剩余电量
    elif Operation_choose == '8':
    print(' 获取剩余电量:')
    os.popen('adb shell dumpsys battery set status 1')
    content=os.popen('adb shell dumpsys battery')
    print(' 剩余电量:',''.join([line.split()[1] for line in content.readlines() if 'level' in line]))
    self.OperationChoose()
    elif Operation_choose == '9':
    print(' 返回')
    else:
    print(' 您的输入有误,请重新输入')
    self.OperationChoose()
    if __name__=='__main__':
    while True:
    app=App()
    app.run()
  • 相关阅读:
    window.onresize绑定事件以及解绑事件
    jqGrid中select带可编辑的
    ROS(机器视觉)
    Python(time模块)
    Python(random模块)
    Python迭代器
    Python生成器
    Python装饰器(函数)
    ROS(URDF机器人建模)
    ROS基础
  • 原文地址:https://www.cnblogs.com/Aluosen/p/11312417.html
Copyright © 2020-2023  润新知