python简单的自动化APP启动时间测试

# coding:utf-8
import os
import time
cmd = 'adb shell am start -W -n com.android.browser/.BrowserActivity'
content = os.popen(cmd)
print("启动APP成功")
for line in content.readlines():
print(line)
if "ThisTime" in line:
StartTime = line.split(":")[1] # 切割取出的时间 thistime :300 以:为分隔符
break
print("你需要的StartTime等于:%s" % StartTime)
time.sleep(3) #休眠3S,关闭APP

cmd = 'adb shell am force-stop com.android.browser'
content = os.popen(cmd) #关闭APP
print("关闭APP成功")


循环测试:
# coding:utf-8

import os
import time

n = 1
while n < 4:
cmd = 'adb shell am start -W -n com.android.browser/.BrowserActivity'
content = os.popen(cmd) # 启动app
print("启动app成功")

for line in content.readlines():
if "ThisTime" in line:
StartTime = line.split(":")[1]
break
print("第%s次的启动时间StartTime 等于: %s" % (n, StartTime))
time.sleep(2) # 休眠2s,关闭app

cmd = 'adb shell am force-stop com.android.browser'
content = os.popen(cmd) # 关闭app
print("关闭app成功")
n += 1
time.sleep(2)
print("------------------测试完成!--------------------")
posted @ 2019-06-04 14:43  年少不经事  阅读(804)  评论(0编辑  收藏  举报