import csv
import os,time
from tqdm import tqdm

class App():
    def __init__(self):
        self.start_app_state = ''
        self.savedata = [('时间戳','耗时')]
        self.get_time = ''

    # 开启app
    def start_app(self):
        cmd = 'adb shell am start -W -n com.ruixing.bbc/com.ruixing.bbc.mvp.ui.activity.FirstActivity'
        self.start_app_state = os.popen(cmd)

    # 停止app
    def stop_app(self):
        cmd = 'adb shell am force-stop com.ruixing.bbc'
        os.popen(cmd)

    # 获取启动时间
    def get_starttime(self):
        for state in self.start_app_state.readlines():
            if 'ThisTime' in state:
                self.get_time = state.split()[1]
                self.show_time()
                break

    # 显示当前时间戳
    def show_time(self):
        now_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
        self.savedata.append((now_time,self.get_time))


    # 保存数据
    def save_data(self):
        with open('APPstartTime.csv','a',newline='') as file:
            write = csv.writer(file)
            write.writerows(self.savedata)

if __name__ == "__main__":
    run = App()
    for k in tqdm(range(1,11)):
        run.start_app()
        time.sleep(3)
        run.get_starttime()
        run.stop_app()
        time.sleep(2)

    run.save_data()
最后修改:2018 年 05 月 09 日 04 : 50 PM
如果觉得我的文章对你有用,请随意赞赏