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'\t{self.n}.{app}')
self.n+=1
App_choose = input('请选择您要开启的APP名称【1-4】:')
if App_choose=='1':
# global Appchoose
print('\t正在开启微信……')
content=os.popen('adb shell am start -W com.tencent.mm/.ui.LauncherUI')
print('\t微信开启成功')
self.Appchoose='com.tencent.mm'
#链家
elif App_choose=='2':
print('\t正在开启链家……')
content=os.popen('adb shell am start -W com.homelink.android/.SplashScreenActivity')
print('\t链家开启成功')
self.Appchoose ='com.homelink.android'
#宝骏
elif App_choose=='3':
print('\t正在开启宝骏……')
content=os.popen('adb shell am start -W com.tjd.Baojun/.Loading')
print('\t宝骏开启成功')
self.Appchoose ='com.tjd.Baojun'
#退出程序
elif App_choose == '4':
print('\t正在退出程序')
exit()
else:
print('您的输入有误,请重新输入')
self.LaunchApp()
print('\t请稍候……')
# 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'\t{self.n}.{Operation}')
self.n+=1
Operation_choose = input('请选择您要进行的操作【1-9】')
print('-' * 64)
#关闭App
if Operation_choose == '1':
print('\t正在关闭App……')
os.popen('adb shell am force-stop %s' % self.Appchoose)
#程序转到后台
elif Operation_choose == '2':
print('\t正在退到后台……')
os.popen('adb shell input keyevent 3')
print('\t退到后台成功')
self.OperationChoose()
#查看启动时间
elif Operation_choose=='3':
print('\t启动时间(ms):',self.ThisTime)
self.OperationChoose()
#查看Cpu
elif Operation_choose == '4':
print('\t查看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('\t正在获取进程号Pid')
content = os.popen('adb shell dumpsys cpuinfo|findstr %s' % self.Appchoose)
print('\t进程号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('\t查看进程流量:')
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("\t接收字节数:", Receiverbytes)
print("\t传输字节数:", Transmitbytes)
print("\t总流量(byte):", Titlebytes, 'byte')
print("\t总流量(Mb):", Titlebytes / 1024, 'Mb')
self.OperationChoose()
#获取进程占用内存
elif Operation_choose == '7':
print('\t进程占用内存:')
content=os.popen('adb shell dumpsys meminfo %s'%self.Appchoose)
print('\tTOTAL:', ''.join([line.split()[1] for line in content.readlines() if 'TOTAL' in line]))
self.OperationChoose()
#获取剩余电量
elif Operation_choose == '8':
print('\t获取剩余电量:')
os.popen('adb shell dumpsys battery set status 1')
content=os.popen('adb shell dumpsys battery')
print('\t剩余电量:',''.join([line.split()[1] for line in content.readlines() if 'level' in line]))
self.OperationChoose()
elif Operation_choose == '9':
print('\t返回')
else:
print('\t您的输入有误,请重新输入')
self.OperationChoose()
if __name__=='__main__':
while True:
app=App()
app.run()
posted @ 2019-08-06 22:53  Aluosen  阅读(225)  评论(0编辑  收藏  举报