码迷,mamicode.com
首页 > 移动开发 > 详细

通过python调用adb命令对app进行测试 启动/停止app

时间:2018-05-11 23:52:36      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:appstore   param   tac   __init__   log   import   comm   lin   开启   

转于博客  https://blog.csdn.net/sunfengye/article/details/77498935    yipianfeng_ye的专

#启动apk
message  = os.popen("adb shell am start -W -n com.qihoo.appstore/.home.MainActivity")
for line in message.readlines():
    if "ThisTime" in line:
        print(line.split(":")[1])


import  os,time
class App():

    def __init__(self,pagename,firstActivity):
        """构造方法"""
        self.pagename = pagename
        self.firstActivty= firstActivity
        self.content="" #执行命令的文本
        self.startTime="" #启动的时间

    def startApp(self):
        """开启app"""
        cmd = "adb shell am start -W -n "+self.pagename+self.firstActivty
        self.content = os.popen(cmd)

    def stopApp(self):
        """停止app"""
        cmd = "adb shell am force-stop "+self.pagename
        os.popen(cmd)

    def getStartTime(self):
        """获取启动时间"""
        for line in self.content.readlines():
            if "ThisTime" in line:
                self.startTime = line.split(":")[1]
                break
        return  self.startTime



通过python调用adb命令对app进行测试 启动/停止app

标签:appstore   param   tac   __init__   log   import   comm   lin   开启   

原文地址:https://www.cnblogs.com/lili414/p/9026437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!