• App测试总脚本1.20


    # -*- 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
    pass
    def run(self):
    self.LaunchApp()
    self.OperationChoose()
    def LaunchApp(self):
    print('-' * 64)
    print('APP名称:')
    print(' 1.微信')
    print(' 2.链家')
    print(' 3.宝骏')
    print(' 4.退出程序')
    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):
    print('-' * 64)
    print('操作选择:')
    print(' 1.关闭App')
    print(' 2.App退到后台')
    print(' 3.查看启动时间')
    print(' 4.查看Cpu')
    print(' 5.获取进程号PID')
    print(' 6.查看进程流量')
    print(' 7.查看进程占用内存')
    print(' 8.查看电量')
    print(' 9.返回')
    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()
  • 相关阅读:
    eclipse 关闭web项目无用校验
    Java7的那些新特性
    Linux内核源码情景分析-wait()、schedule()
    android canvas 画图笔记
    android启动第一个界面时即闪屏的核心代码(两种方式)
    leetCode(24):Binary Search Tree Iterator
    12:打印 1 到最大的 n 位数
    Android仿QQ ios dialog,仿QQ退出向上菜单
    iOS UI16_数据持久化
    Android自己定义百度地图缩放图标
  • 原文地址:https://www.cnblogs.com/Aluosen/p/11290561.html
Copyright © 2020-2023  润新知