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中用折线图显示出来,观察有无突变

  • 相关阅读:
    沟通,你都做了什么
    Markdown,你只需要掌握这几个
    一周心态-情景联想
    一周心态-漫谈计划之死
    我的Git之旅(1)---git安装、github注册以及一些基本命令
    我的20132014
    Python 笔记——4 条件控制
    Python 笔记——3 数据类型
    Python 笔记——1语法分析
    纯CSS实现兼容ie6以上的圆角头像
  • 原文地址:https://www.cnblogs.com/lexus168/p/12689954.html
Copyright © 2011-2022 走看看