开源云真机平台-Sonic平台-python自定义脚本-批量导出monkey测试日志并抓取logcat日志

【主要功能】

开源云真机平台-Sonic平台-python自定义脚本:

1、批量导出monkey测试日志

2、抓取logcat日志

3、将导出的日志批量复制到局域网内的制定电脑上进行收集整理;

4、每一台设备的monkey日志、logcat日志单独存储,并以日期+设备序列号的方式保存;

【详细代码】

python 复制代码
# -*- coding: utf-8 -*- 
import os
import subprocess
import time
import threading
import os,sys,json
udId = sys.argv[1:][1]
text1 = sys.argv[1:][2]


ftp_path = r"\\10.11.12.2\share\MonkeyLogs"
print("ftp_path=" + ftp_path)

current_time = time.strftime("%Y%m%d_%H%M%S")
date_path = time.strftime("%Y%m%d_%H")
pc_path = os.path.join(ftp_path, f"MonkeyLogs_{date_path}", current_time + "_" + udId)

if not os.path.exists(ftp_path):
    os.makedirs(ftp_path)
if not os.path.exists(pc_path):
    os.makedirs(pc_path)


def run_command(command):
    print(f"command={command}")
    os.system(command)
    time.sleep(1)

def run_test():
    print(f"monkey logs uploading...")
    run_command(f"""adb -s {udId} shell settings put global policy_control null""")
    run_command(f"""adb -s {udId} pull /sdcard/MonkeyLog.text {pc_path}""")
    run_command(f"""adb -s {udId} pull /sdcard/MonkeyError.text {pc_path}""")
    run_command(f"""adb -s {udId} shell sleep 3""")
    thread = threading.Thread(target=logcat, args=())
    thread.start()
  
    print("60S后重启.")
    time.sleep(60)
    run_command(f"""adb -s {udId} reboot""")
    print(f"android device rebooting...")
    


def logcat():
    print(f"logcat logs uploading...")
    run_command(f"""adb -s {udId} logcat -v time > {pc_path}\\{udId}_logcat.log &""")

if __name__ == "__main__":
    run_test()
  



          

【运行效果】

【导出结果】

相关推荐
AI云原生10 分钟前
云原生系列Bug修复:Docker镜像无法启动的终极解决方案与排查思路
运维·服务器·python·docker·云原生·容器·bug
万粉变现经纪人2 小时前
如何解决 pip install -r requirements.txt 私有索引未设为 trusted-host 导致拒绝 问题
开发语言·python·scrapy·flask·beautifulsoup·pandas·pip
qq_479875432 小时前
C++ std::Set<std::pair>
开发语言·c++
查士丁尼·绵3 小时前
笔试-九宫格三阶积幻方
python·九宫格·三阶积幻方
云知谷5 小时前
【C++基本功】C++适合做什么,哪些领域适合哪些领域不适合?
c语言·开发语言·c++·人工智能·团队开发
l1t6 小时前
DeepSeek辅助利用搬移底层xml实现快速编辑xlsx文件的python程序
xml·开发语言·python·xlsx
大飞记Python6 小时前
部门管理|“编辑部门”功能实现(Django5零基础Web平台)
前端·数据库·python·django
C_Liu_7 小时前
C++:list
开发语言·c++
my rainy days7 小时前
C++:友元
开发语言·c++·算法
小梁努力敲代码7 小时前
java数据结构--List的介绍
java·开发语言·数据结构