当前位置: 首页 > news >正文

第6.3节 iOS Agent开发<一>

iOS由于其系统的特殊性,很多操作需要在Mac电脑上完成,所以也就无法部署到容器上。于是将iOS Agent开发成单独的服务,由Django开发,对外提供http请求接口,部署到Mac机器上以响应精准测试平台的请求。

6.3.1 Agent整体架构介绍

1,Agent功能架构图

2,功能模块介绍

(1)OC项目模块
针对 Object-C项目的生成覆盖率相关的操作,包括Clone项目,构建项目(需要构建后的Class文件),上传覆盖率文件(此文件为打包后的zip文件),XcodeCoverage生成覆盖率报告,以及解析覆盖率报告数据(取行覆盖率相关数据),下载覆盖率报告,以便精准测试平台展示。
  • 构建项目生成报告类iOSCovOperations:
# coding=utf-8
import os,shutil
import zipfilefrom iOSOCAndSwiftAgent.UtilsOperation.const import DEBUG_SERVICEclass iOSCovOperations(object):"""iOS覆盖率相关操作"""def getGcnoFilePath(self,propath):"""获取项目构建后的gcno文件路径"""envfilepath=propath+"Pods/XcodeCoverage/env.sh";gcnopath=""rfile=open(envfilepath)line=rfile.readline()while line:if line.find("OBJECT_FILE_DIR_normal")>-1:gcnopath=line[line.index("=")+2:line.rindex("\"")]breakline=rfile.readline()gcnopath=gcnopath+"/arm64"return gcnopathdef copygcnofile(self,propath):"""拷贝构建后的文件:param propath::return:"""# 4,拷贝构建后的代码到指定路径gcnopath=propath+"Pods/XcodeCoverage/gcnofolder"if os.path.exists(gcnopath):shutil.rmtree(gcnopath)shutil.copytree(self.getGcnoFilePath(propath),gcnopath)def buildPorject(self,propath):"""构建iOS项目"""curpath = os.getcwd();scriptpath=""print("当前目录是:"+curpath)if DEBUG_SERVICE.find("Agent")>-1:#写死Agent上的路径scriptpath="/Users/****/ScriptFiles/"else:#本机debugscriptpath="/Users/*****/ScriptFiles/"os.chdir(propath)# 1,pod安装os.system("pod install")# 2,拷贝构建脚本os.system("cp "+scriptpath+"EnterpriseExportOptionsPlist.plist "+propath+"EnterpriseExportOptionsPlist.plist")os.system("cp "+scriptpath+"xcodebuild.sh "+propath+"xcodebuild.sh")os.system("chmod 777 "+propath+"xcodebuild.sh")# 获取项目名称proname=""for f in os.listdir(propath):print("file name:"+f)if f.find("xcworkspace")>-1:proname=f[0:f.index(".")]break#3,构建项目if len(proname)>0:os.system(propath+"xcodebuild.sh "+proname+" &")else:print("项目中没有项目文件,请检测项目内容是否有遗漏!")# # 4,拷贝构建后的代码到指定路径# gcnopath=propath+"Pods/XcodeCoverage/gcnofolder"# if os.path.exists(gcnopath):#     shutil.rmtree(gcnopath)# shutil.copytree(self.getGcnoFilePath(propath),gcnopath)#5,切换回当前目录os.chdir(curpath)return Truedef createiOSCovReport(self,propath,covdatapath):"""根据覆盖率数据文件,生成覆盖率执行"""#1,拼出gcno文件路径gcnopath=propath+"Pods/XcodeCoverage/gcnofolder"#2,拷贝构建后的文件到覆盖率文件中for fileName in os.listdir(gcnopath):srcFile = os.path.join(gcnopath,fileName)tarFile = os.path.join(covdatapath,fileName)shutil.copyfile(srcFile,tarFile)#3,覆盖率报告路径covreppath=propath+"Pods/XcodeCoverage/tempreports/"+covdatapath[covdatapath.rindex("/")+1:len(covdatapath)]if not os.path.exists(covreppath):os.makedirs(covreppath)#4,重写env.sh文件内容envfile=propath+"Pods/XcodeCoverage/env.sh"os.remove(envfile)wrfile=open(envfile,"w+")#写入BUILT_PRODUCTS_DIRwrfile.write("export BUILT_PRODUCTS_DIR=\""+covreppath+"\"\t\n");#写入export CURRENT_ARCH=""wrfile.write("export CURRENT_ARCH=\"\"\t\n");#写入OBJECT_FILE_DIR_normalwrfile.write("export OBJECT_FILE_DIR_normal=\""+covdatapath+"\"\t\n");#写入OBJROOTwrfile.write("export OBJROOT=\"\"\t\n");#写入SRCROOTwrfile.write("export SRCROOT=\""+propath+"\"\t\n");wrfile.close()#5,执行生成报告命令getcovcmd=propath+"Pods/XcodeCoverage/getcov"os.system(getcovcmd)return covreppathdef createXcodeCoverageReport(self,propath,covdatapath):"""根据覆盖率数据,合并报告生成最终的报告"""gedatapath = propath + "Pods/XcodeCoverage/coverage"if not os.path.exists(gedatapath):os.makedirs(gedatapath)xcreppath = propath + "Pods/XcodeCoverage/report"if not os.path.exists(xcreppath):os.makedirs(xcreppath)#遍历覆盖率数据文件夹,分别生成报告count=0for file in os.listdir(covdatapath):if file.find("arm")>-1:tempcovpath=covdatapath+"/"+fileprint("数据文件:"+tempcovpath)temprep=self.createiOSCovReport(propath,tempcovpath)#拷贝生成的Coverage.info文件os.system("cp "+temprep+"/lcov/Coverage.info "+gedatapath+"/Coverage"+str(count)+".info")count=count+1# 生成整体覆盖率的报告mercmd=propath+"Pods/XcodeCoverage/mergecov"curpath = os.getcwd();if DEBUG_SERVICE.find("Agent")>-1:#写死Agent上的路径scriptpath="/Users/****/ScriptFiles/"else:#本机debugscriptpath="/Users/*****/ScriptFiles/"os.system("cp "+scriptpath+"mergecov "+mercmd)os.system("chmod 777 "+mercmd)os.system(mercmd)# 将生成的测试报告打包output_filename=propath+"report.zip"zipf = zipfile.ZipFile(output_filename, 'w')pre_len = len(os.path.dirname(xcreppath))for parent, dirnames, filenames in os.walk(xcreppath):for filename in filenames:pathfile = os.path.join(parent, filename)arcname = pathfile[pre_len:].strip(os.path.sep)zipf.write(pathfile, arcname)zipf.close()return xcreppathdef getCovData(self,reppath):"""获取覆盖率报告中的数据:param reppath::return:"""file=open(reppath,"r")line=file.readline()covlines=""totallines=""covlinerate=""covfuns=""totalfuns=""covfunrate=""while line:line=file.readline()if line.find("headerCovTableEntry")>-1:if len(covlines)==0:covlines=line[line.index(">")+1:line.rindex("<")]continueif len(covlines)>0 and len(totallines)==0:totallines=line[line.index(">")+1:line.rindex("<")]continueif line.find("%")>-1 and len(covlinerate)==0:covlinerate=line[line.index(">")+1:line.rindex("<")]continueif len(covfuns)==0:covfuns=line[line.index(">")+1:line.rindex("<")]continueif len(covfuns)>0 and len(totalfuns)==0:totalfuns=line[line.index(">")+1:line.rindex("<")]continueif line.find("%")>-1 and len(covfunrate)==0:covfunrate=line[line.index(">")+1:line.rindex("<")]breakrepdata={"totalines":totallines,"covlines":covlines,"covlinerate":covlinerate,"totalfuns":totalfuns,"covfuns":covfuns,"covfunrate":covfunrate}return repdataif __name__ == '__main__':iosopr=iOSCovOperations()propath="/Users/****/ghdropmenudemo/"
covdatapath="/Users/****/ghdropmenudemo/Pods/XcodeCoverage/tempcovdata"iosopr.getCovData(propath+"Pods/XcodeCoverage/report/index.html")

此方案主要在构建项目上比较耗时,可以采取在公司打包平台打包后上传构建文件,以节省时间;同时上传的覆盖率数据文件也较大,由于公司的项目是Swift的,这个模块也没有再继续优化,使用测试Demo验证,相关功能没有问题
http://www.dtcms.com/a/403206.html

相关文章:

  • 多多返利网站建设程序中装建设股票
  • 处理限流、缓存与数据一致性:1688 API 实时数据采集的技术细节
  • 网站建设需要什么编程语言wordpress 飞龙博客 许愿墙
  • Pythoner 的Flask项目实践-绘制点/线/面并分类型保存为shpfile功能(Mapboxgl底图)
  • 汽车渗透测试自动化工具和过程
  • 南京大学 LLM开发基础(二)大语言模型解析 -- 基于HF LlaMA实现的讲解
  • 《企业级知识图谱从0到1的开发实录》
  • Java虚拟机——垃圾回收算法
  • 电商平台正在建设中网站页面营销策略英文
  • MCP协议:重构AI协作的未来,打破模型边界的技术革命!
  • 做网站要备案吗宁波seo公司排名榜
  • UE5 GAS 预测框架解析
  • SavingsPlan模型优化:AWS成本管理的性能飞跃
  • 从入门到精通【Redis】理解Redis持久化
  • 郑州做网站元辰提升学历的正规平台
  • 什么是无盘工作站?RARP用于无盘工作站等设备在启动时获取自己的 IP 地址。
  • Python在不同领域的应用案例
  • 《Muduo网络库:CMake构建集成编译环境》
  • IDEA services面板+自动运行项目
  • 云原生网关Higress介绍与部署指南
  • 手机网站是怎么做的图片设计制作软件
  • 亚像素边缘检测思想
  • 云服务器需要备案吗?如何备案
  • AutoDL使用
  • 检察院门户网站建设方案磁力库
  • 时序数据库选型指南:Apache IoTDB引领数字化转型新时代——核心概念与关键技术解析
  • Hash算法全解析:原理、安全风险与全球法规要求
  • odoo阿里云大模型多字段内容翻译
  • 【硬核对比】Hive与MySQL全方位深度对比:从架构、SQL语法到应用场景,搞懂选型不踩坑
  • 【Java并发】深入解析ConcurrentHashMap