#Encoding:utf-8ImportCSVImportOSImport TimeclassApp (object):def __init__(self): self.content=""Self.starttime=0#Launch App defLaunchapp (self): cmd='adb shell am start-w-n com.android.browser/. Browseractivity'self.content=os.popen (cmd)#Stop App defStopapp (self):#cmd = ' adb shell am force-stop com.android.browser 'cmd ='adb shell input keyevent 3'os.popen (cmd)#Get start time defGetlaunchedtime (self): forLineinchself.content.readlines ():if "Thistime" inchLine:self.startTime= Line.split (":") [1] Break returnSelf.starttime#Control classclassController (object):def __init__(self, count): Self.app=App () self.counter=Count Self.alldata= [("timestamp","ElapsedTime")] #one-time test process deftestprocess (self): self.app.LaunchApp () time.sleep (5) Elpasedtime=self.app.GetLaunchedTime () self.app.StopApp () Time.sleep (3) CurrentTime=Self.getcurrenttime (Self.alldata.append) (CurrentTime, Elpasedtime)#perform the test process multiple times defRun (self): whileSelf.counter >0:self.testprocess () self.counter= Self.counter-1#gets the current timestamp defGetCurrentTime (self): CurrentTime= Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())returncurrenttime#Storage of Data defsavedatatocsv (self): CSVFile= File ('Starttime2.csv','WB') Writer=Csv.writer (csvfile) writer.writerows (self.alldata) csvfile.close ()if __name__=="__main__": Controller= Controller (10) Controller.run () controller. Savedatatocsv ()
App performance test (startup time)