• APP专项测试1 ---启动时间python脚本及分析


    import os
    import time
    import csv
    
    #app类
    class APP(object):
    
        #定义一个变量接收cmd返回内容
        def __init__(self):
            self.content = ""
            self.startTime = 0
    
    
        #启动app方法
        def lauchApp(self):
            cmd = "adb shell am start -W -n com.example.shineapp/.activity.SplashActivity"
            self.content = os.popen(cmd)
            return self.content
    
    
        #停止app
        def stopAPP(self):
            #冷启动停止
         #cmd
    = "adb shell am force-stop com.example.shineapp" #热启动停止
         cmd = "adb shell input keyevent 3"
         os.popen(cmd)
    #获取启动时间 def GetLauchedTime(self): for line in self.content.readlines(): if "ThisTime" in line: self.startTime = line.split(":")[1] break return self.startTime #控制类 class Controller(object): def __init__(self,count): #count是测试的次数 self.app = APP() self.counter = count self.alldata = [("timestamp","elpasedtime")] #定义一个执行过程,首先需要启动app,所以定义一个初始化函数实例化app类 def testprocess(self): # os.popen(r"cd D:Program FilesNoxin") # os.popen("nox_adb.exe connect 127.0.0.1:62001") # time.sleep(2) self.app.lauchApp() time.sleep(5) elpasedtime = self.app.GetLauchedTime() self.app.stopAPP() time.sleep(3) currenttime = self.getCurrentTime() self.alldata.append((currenttime,elpasedtime)) #多次执行的测试过程 def run(self): while self.counter > 0 : self.testprocess() self.counter = self.counter - 1 #获取当前时间戳 def getCurrentTime(self): currentTime = time.strftime("%Y-%m-%d %H:%M:%S") return currentTime #数据的存储 def SaveDataToCsv(self): csvfile = open("startTime.csv","wb") writer = csv.writer(csvfile) writer.writerows(self.alldata) csvfile.close() if __name__ == '__main__': controller = Controller(10) controller.run() controller.SaveDataToCsv()

    将输出的结果在excel中用折线图显示出来,观察有无突变

  • 相关阅读:
    【题解】Luogu1308 统计单词数
    【题解】Luogu1739 表达式括号匹配
    等待
    封城日记
    【题解】luoguP5717三角形分类
    【题解】LuoguP1059明明的随机数
    我是一个跳表
    【JVM故事】了解JVM的结构,好在面试时吹牛
    【JVM故事】一个Java字节码文件的诞生记
    Java多线程通关——基础知识挑战
  • 原文地址:https://www.cnblogs.com/lexus168/p/12689954.html
Copyright © 2020-2023  润新知