This test can use the ADB tool, the ADB installation method
Test strategy
- First boot after installation
- regular cold boot
-
Hot start (usually rarely tested)
test methods for 1 and 2 Step 1: Enter the following command in cmd
adb Logcat * > D:\log.txt
Step 2: Again on the phone open the apk,apk that will be tested after the boot is complete, cmd press CTRL + C to end the import log
Step 3: Find the log.txt,ctrl+f on the D drive , enter displayed (search displayed word), displayed after display time, some apps have multiple displayed, start time is the sum of all displayed time
Start time here is 609 + 738 (ms)
There is also a way to get to the time of the three-to-one, as follows Step I: Get the package name of the test apk (can ask for development), can be obtained by ADB,
1) Start the APK
2) Enter the command in cmd:
adb shell Dumpsys window W | findstr \ | findstr name =
The Gets the following, where name is followed by the required package name/component
msurface=surface (name=com.sina.weibo/com.sina.weibo.visitormaintabactivity)
Step Two: Start the apk in cmd Input command, there is a start time
adb shell am start-w-n com.sina.weibo/. Visitormaintabactivity
Output is as follows, where Thistime is the total time to start
status:okactivity:com.sina.weibo/ . Visitormaintabactivitythistime:1326totaltime:1326waittime:1354complete
After all, the hand has to wait for special trouble every time, then use the Python script to achieve the start time for each. The code is as follows
#!/user/bin/python# _*_ coding:utf-8 _*_import csvimport reimport osimport timepackage_activity= "com.sina.weibo/. Visitormaintabactivity "PackageName =" Com.sina.weibo "Runnum = 10class App (): Def __init__ (self): Self.content = "" Self.starttime = 0 Self.flag = 1 def lauchapp (self): cmd = "adb shell am start-w-n" + packag E_activity self.content = Os.popen (cmd) def stopapp (self): if Self.flag = = 1:cmd = "adb shell Am Force-stop "+ packagename else:cmd =" adb shell input keyevent 3 "Os.popen (CMD) def getl Aunchedtime (self): for line in Self.content.readlines (): If ' thistime ' in Line:self.star Ttime = Line.split (":") [1] break print (self.starttime) return Self.starttimeclass Controller (object): Def __init__ (self): Self.app = App () self.counter = 0 Self.laughtime = [("Timestamp", "El Apsedtime ")] def testprocess (Self): self.app.LauchApp () Elpasedtime = Self.app.GetLaunchedTime () time.sleep (3) self.app.Sto Papp () CurrentTime = Self.getcurrenttime () self.laughtime.append ((currenttime,elpasedtime)) def run (self) : While Self.counter > 0:self.testprocess () self.counter = Self.counter-1 def getcur Renttime (self): CurrentTime = Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ()) return currenttime def Savedatatocsv (self): if Self.app.flag = = 1:csvfile = File ("Coldstart_time.csv", "WB") Else: CSVFile = File ("Hotstart_time.csv", "WB") writer = Csv.writer (csvfile) writer.writerows (self.laughtim e) csvfile.close () def coldlaugh_run (): Controller = Controller () Controller.counter = Runnum Controller.ap P.flag = 1 Controller.run () controller. Savedatatocsv () def hotlaugh_run (): Controller = Controller () Controller.counter = Runnum conTroller.app.flag = 0 Controller.run () controller. Savedatatocsv () if __name__ = = "__main__": Coldlaugh_run () Hotlaugh_run ()
Description under:
where Def savedatatocsv (self) is the file ("Hotstart_time.csv", "WB") in this function, Python3 changes the file to open
App performance test start-up time (Android)