• 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()
  • 相关阅读:
    MyBatis学习(一)
    ORM框架
    Java 核心技术点之注解
    git 分支 合并
    TensorFlow——零碎语法知识点
    TensorFlow——深入MNIST
    tensorflow——MNIST机器学习入门
    TensorFlow——小练习:feed
    TensorFlow——小练习:counter
    TensorFlow——交互式使用会话:InteractiveSession类
  • 原文地址:https://www.cnblogs.com/aqiuarcadia/p/7440944.html
Copyright © 2020-2023  润新知