zoukankan      html  css  js  c++  java
  • 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中用折线图显示出来,观察有无突变

  • 相关阅读:
    大作文-学以”成人”
    方案类--博物院整改意见
    归纳概括-我国中小学开展研学旅行活动的特点
    短文-网络新一代
    短评
    讲话稿-文明素养教育主题宣传
    检验用户单点登录方案解决
    Spring @Transactional注解
    RPC-局限于java的RMI
    Redis缓存雪崩、击穿、穿透的问题和解决方式
  • 原文地址:https://www.cnblogs.com/lexus168/p/12689954.html
Copyright © 2011-2022 走看看