Launch time of APP special test

Source: Internet
Author: User

#Coding:utf-8ImportOs,csv,timeclassApp (object):def __init__(self): self.content="'Self.starttime=0#Launch App    defLaunchapp (self): cmd='adb shell am start-w-N com.android.chrome/org.chromium.chrome.browser.chrometabbedactivity'self.content=os.popen (cmd)#Stop App    defStopapp (self): cmd='adb shell am force-stop com.android.chrome'        #cmd= ' adb shell keyevent 3 'os.popen (cmd)defGetlaunchedtime (self):#Loop with Thistime this line         forLineinchself.content.readlines ():if 'Thistime'inchLine:self.startTime=line.split (':') [1]                 Break        returnSelf.starttimeclassController (object):def __init__(self,count): Self.app=App () self.counter=Count#Timestamp: This time it's starting in a few seconds.        #elapsedtime Time ConsumingSelf.alldata = [("timestamp","ElapsedTime")]        #one-time test process    deftestprocess (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))defRun (self): whileSelf.counter>0:self.testprocess () self.counter=self.counter-1defGetCurrentTime (self):#Gets the current timestamp methodCurrentTime = Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())#gets the current timestamp        returncurrenttimedefsavedatatocsv (self): CSVFile=file ('Starttime.csv','WB') Write=Csv.writer (csvfile) write.writerows (self.alldata)#Write.writerow is writing to a linecsvfile.close ()if __name__=='__main__': Controller=controller (5)#Number of executionsController.run () controller. Savedatatocsv ()
Start Time
First step: Create two classes of appsclass:#the class of worklaunchapp Stopapp getlaunchtime Controllerclass:#the class that is calledRun Collectalldata savadatatocsv-----------------------------------------Step Two:defLaunchapp (self): Start the app method cmd='adb shell am start-w-N com.android.chrome/org.chromium.chrome.browser.chrometabbedactivity'self.content=Os.popen (CMD) executes the Shell's module command, gets the return value of contentdefStopapp (self): Stop app method cmd='adb shell am force-stop com.android.chrome'os.popen (CMD) step three: Because the Getlaunchtime method needs to use the content of the Launchapp (self), you need to initialize a variableclassApp ():def __init__(self): self.content="'Fourth Step:defGetlaunchedtime (self): forLineinchself.content.readlines (): Content loopingif 'Thistime'inchLine: If this row comes with Thistime self.starttime=line.split (':') [1] then divide the line with ":" and assign the value to StartTime BreakJumpreturnSelf.starttime return thistime time Fifth step: Initialize Self.starttime=0 to be used in other ways. Sixth step: Controller () class operations6.1:classController ():def __init__(self,count): Self.app=app ()#after instantiation, you can use other classes (APP) methods in this class. Self.counter=count#set the number of runs6.2:    #one-time test process    deftestprocess (self): self.app.launchApp () Self.app.GetLaunchedTime () self.app.StopApp ()6.3: A test process that executes multiple timesdefRun (self): whileSelf.counter>0:self.testprocess () self.counter=self.counter-1
Start Time Notes

Launch time of APP special test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.