标签:pap acs popen 情况 博客 exception adb shell stop 应用
一、应用的启动方式
通常来说,启动方式分为两种:冷启动和热启动。
1、冷启动:当启动应用时,后台没有该应用的进程,这时系统会重新创建一个新的进程分配给该应用,这个启动方式就是冷启动。
2、热启动:当启动应用时,后台已有该应用的进程(例:按back键、home键,应用虽然会退出,但是该应用的进程是依然会保留在后台,可进入任务列表查看),所以在已有进程的情况下,这种启动会从已有的进程中来启动应用,这个方式叫热启动。
特点
1、冷启动:冷启动因为系统会重新创建一个新的进程分配给它,所以会先创建和初始化Application类,再创建和初始化MainActivity类(包括一系列的测量、布局、绘制),最后显示在界面上。
2、热启动:热启动因为会从已有的进程中来启动,所以热启动就不会走Application这步了,而是直接走MainActivity(包括一系列的测量、布局、绘制),所以热启动的过程只需要创建和初始化一个MainActivity就行了,而不必创建和初始化Application,
因为一个应用从新进程的创建到进程的销毁,Application只会初始化一次。
二、测试方式
启动APP命令 adb shell am start -W -n package/activity(冷启动、热启动都用这个)
停止APP命令 adb shell am force-stop package:冷启动,sdb shell input keyevent 3(手机上的back键):热启动
获取手机里面打开应用的包名、actiivty名字 adb logcat | grep START (git base下使用)
三、自动化脚本的实现
两种实现思路:
1、获取命令执行时间,作为启动时间参考值
2、在命令执行前后加上时间戳,以差值作为参考值
类设计:
App class:LaunchApp、StopApp、GetLaunchTime
Controller class : run、collectAllData、SaveToDataCSV
#/usr/bin/python
#encoding:utf-8
import csv
import os
#app控制类
import time
class App():
def __init__(self): #初始化
self.content = ""
self.startTime = 0
#启动app
def launchApp(self):
cmd = ‘adb shell am start -W -n com.aoshang.exception/.SplashActivity‘
self.content = os.popen(cmd) #执行命令
#停止app
def stopApp(self):
cmd = ‘adb shell am force-stop com.aoshang.exception‘
os.popen(cmd)
#得到启动时间
def getLaunchTime(self):
for line in self.content.readlines():
if "ThisTime" in line:
self.startTime = line.split(":")[1]
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()
time.sleep(5)
elapsedtime = self.app.getLaunchTime()
self.app.stopApp()
time.sleep(3)
currentTime = self.getCurrentTime()
self.allData.append((currentTime,elapsedtime)) #保存数据到元组中
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
def saveDataToCSV(self):
csvFile = file("startTime1.csv","wb")
writer = csv.writer(csvFile)
writer.writerows(self.allData)
csvFile.close()
#运行方法
if __name__ == "__main__":
controll = Controller(10);
controll.run()
controll.saveDataToCSV()
启动时间判断方式:
取竞品去比较参考
各版本之间对比
参考博客:
http://www.cnblogs.com/xunzhi/p/5794793.html
标签:pap acs popen 情况 博客 exception adb shell stop 应用
原文地址:http://www.cnblogs.com/wtao741/p/6238492.html