zoukankan      html  css  js  c++  java
  • adb测试-APP启动时间,写入csv

    #! /usr/bin/env python
    #! -*- cording:utf-8 -*-
    import  os
    import  time
    import  csv
    
    class App(object):
        def __init__(self):
            self.content=""
            self.starttime=""
        #启动APP
        def launchApp(self):
            cmd='adb shell am start -W -n com.sec.android.app.sbrowser/.SBrowserMainActivity'
            self.content=os.popen(cmd)
         #停止APP
        def StopApp(self):
            cmd ='adb shell am force-stop com.sec.android.app.sbrowser'
            os.popen(cmd)
        def GetLaunchedTime(self):
             for line in self.content.readlines():
                 if "ThisTime" in line:
                     self.starttime=line.split(":")[1]
                     #拆分切片启动时间,取thistime后面的时间值
                     break
             return  self.starttime
    #控制类
    class Controller(object):
        def __init__(self,count):
            self.app=App()
            self.count=count
            self.alldata=[("timestamp","elapsedtime")]
    #单次测试过程
        def testprocess(self):
            self.app.launchApp()
            elpasedtime=self.app.GetLaunchedTime()
            self.app.StopApp()
            currenttime=self.getCurrentTime()
            self.alldata.append((currenttime,elpasedtime))
    #多次执行测试过程
        def run(self):
            while self.count>0:
                self.testprocess()
                self.count=self.count-1
    
     #获取当前的时间戳
        def getCurrentTime(self):
            currentTime=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
            return currentTime
    #根本原因是Python版本问题python2.x中要求用‘wb’,python3.x中要求用'w',如果写成wb则会报错,要写成w
        #2.75可以写wb
        def SaveDataToCSV(self):
            with open("startTime.csv","w") as f:
                writer = csv.writer(f)
                writer.writerows(self.alldata)
    #写入
    
    
    
    if __name__=='__main__':
        controller=Controller(3)
        controller.run()
        controller.SaveDataToCSV()
  • 相关阅读:
    Python自学之路-面试题
    k8s学习笔记之三:configmap和secret
    k8s学习笔记之二:Pod
    k8s学习笔记之四:使用kubeadm配置Ingress
    k8s学习笔记之一:使用kubeadm安装k8s集群
    HTTP content-type
    Json对象和Json字符串的区别
    .net 5+ 知新:【2】 .Net Framework 、.Net 、 .NET Standard的概念与区别
    Log4net和Nlog
    通过系统存储过程手动执行SQL Server中的Job
  • 原文地址:https://www.cnblogs.com/aqiuarcadia/p/7440944.html
Copyright © 2011-2022 走看看