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

  • 相关阅读:
    JAVA:连接池技术说明以及MVC设计模式理解
    SoftLayer®凭借Flex Images™消融物理与虚拟服务器之间的界线
    InternetExplorer 表单及用户名密码提交
    devStack
    windows平台vhd磁盘文件挂载
    xen vhd操作工具source code研读
    windows 基于命令行制作vhd虚拟磁盘
    vhd镜像格式及vhd-util工具应用
    mongoDB windows reinstall add auth
    MongoDb Windows linux平台环境及主流编程语言驱动安装同时配置mongoDb的远程连接
  • 原文地址:https://www.cnblogs.com/lexus168/p/12689954.html
Copyright © 2011-2022 走看看