app專項測試之啟動時間

來源:互聯網
上載者:User

標籤:event   目前時間   readline   post   pos   pre   迴圈   __name__   shell   

# coding: utf-8import os,csv,timeclass App(object):    def __init__(self):        self.content=‘‘        self.startTime=0    #啟動APP    def launchApp(self):        cmd=‘adb shell am start -W -n com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity‘        self.content=os.popen(cmd)        #停止APP    def StopApp(self):        cmd=‘adb shell am force-stop com.android.chrome‘        # cmd=‘adb shell keyevent 3‘        os.popen(cmd)    def GetLaunchedTime(self):        #迴圈帶有ThisTime這一行        for line in self.content.readlines():            if ‘ThisTime‘in line:                self.startTime=line.split(‘:‘)[1]                break        return self.startTimeclass Controller(object):    def __init__(self,count):        self.app=App()        self.counter=count        # timestamp:這次是從幾分幾秒開始的        # elapsedtime耗時        self.alldata = [("timestamp", "elapsedtime")]        #單次測試過程    def testprocess(self):        self.app.launchApp()        time.sleep(3)        elpasedtime =self.app.GetLaunchedTime()        self.app.StopApp()        time.sleep(5)        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", time.localtime())        #擷取當前的時間戳記        return currentTime    def SaveDataToCSV(self):        csvfile=file(‘startTime.csv‘, ‘wb‘)        write=csv.writer(csvfile)        write.writerows(self.alldata) #write.writerow是向一行寫        csvfile.close()if __name__ == ‘__main__‘:    controller=Controller(5) #執行次數    controller.run()    controller.SaveDataToCSV()
啟動時間
第一步:建立兩個類      APP class: #幹活的類          LaunchApp          StopApp          GetlaunchTime      Controller class:#調用的類          run          collectAllData          SavaDataToCSV-----------------------------------------第二步:  def launchApp(self): 啟動APP方法        cmd=‘adb shell am start -W -n com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity‘        self.content=os.popen(cmd) 執行shell的模組命令,擷取傳回值content   def StopApp(self): 停止APP方法        cmd=‘adb shell am force-stop com.android.chrome‘        os.popen(cmd)第三步:因為 GetlaunchTime方法需要用到launchApp(self)的content所以需要初始化一個變數class App():    def __init__(self):        self.content=‘‘第四步: def GetLaunchedTime(self):        for line in self.content.readlines(): content內容中迴圈            if ‘ThisTime‘in line: 如果這一行帶有ThisTime                self.startTime=line.split(‘:‘)[1]則把這一行以“:”切分,賦值給startTime                break 跳出        return self.startTime 返回ThisTime後的時間第五步:初始化self.startTime=0以待其他方法使用。第六步:Controller()類操作    6.1:    class Controller():        def __init__(self,count):            self.app=App() #執行個體化後就可以在本類中使用其他類( app)的方法了。            self.counter=count #設定啟動並執行次數    6.2:    #單次測試過程    def testprocess(self):        self.app.launchApp()        self.app.GetLaunchedTime()        self.app.StopApp()    6.3:多次執行的測試過程        def run(self):        while self.counter>0:            self.testprocess()            self.counter=self.counter-1
啟動時間備忘

 

app專項測試之啟動時間

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.