1. 首先贴上使用Xmind制作的测试用例格式范本
  2. 读取Xmind文件的代码为
ReadXmind = xmind_to_dict(FileName)
  1. 在读取Xmind编写的测试用例时,发现Python读取出来的字符串结构较复杂,因此特地将读取出来的字符串重新赋值进行测试,循环拿到最后的预置条件,测试步骤,实际结果
import jsonpath
ReadXmind = [{'title': 'sheet', 'topic': {'title': '文件名', 'topics':[{'title': 'sheet名1', 'topics':[{'title': '模块1', 'topics': [{'title': '功能1', 'topics': [{'title': '测试点1', 'topics': [{'title': '预置条件1', 'topics': [{'title': '测试步骤1', 'topics': [{'title': '预期结果1'}]}]}]}, {'title': '测试点2', 'topics': [{'title': '预置条件2', 'topics': [{'title': '测试步骤2', 'topics': [{'title': '预期结果2'}]}]}, {'title': '预置条件3', 'topics': [{'title': '测试步骤3', 'topics': [{'title': '预期结果3'}]}]}]}]}, {'title': '功能2', 'topics': [{'title': '测试点3', 'topics': [{'title': '预置条件4', 'topics': [{'title': '测试步骤4', 'topics': [{'title': '预期结果4'}]}]}]}, {'title': '测试点4', 'topics': [{'title': '预置条件5', 'topics': [{'title': '测试步骤5', 'topics': [{'title': '预期结果5'}]}]}, {'title': '预置条件6', 'topics': [{'title': '测试步骤6', 'topics': [{'title': '预期结果6'}]}]}]}]}]}, {'title': '模块2', 'topics': [{'title': '功能3', 'topics': [{'title': '测试点5', 'topics': [{'title': '预置条件7', 'topics': [{'title': '测试步骤7', 'topics': [{'title': '预期结果7'}]}]}]}, {'title': '测试点6', 'topics': [{'title': '预置条件8', 'topics': [{'title': '测试步骤8', 'topics': [{'title': '预期结果8'}]}]}, {'title': '预置条件9', 'topics': [{'title': '测试步骤9', 'topics': [{'title': '预期结果9'}]}]}]}]}, {'title': '功能4', 'topics': [{'title': '测试点7', 'topics': [{'title': '预置条件10', 'topics': [{'title': '测试步骤10', 'topics': [{'title': '预期结果10'}]}]}]}, {'title': '测试点8', 'topics': [{'title': '预置条件11', 'topics': [{'title': '测试步骤11', 'topics': [{'title': '预期结果11'}]}]}, {'title': '预置条件12', 'topics': [{'title': '测试步骤12', 'topics':[{'title': '预期结果12'}]}]}]}]}]}]}, {'title': 'sheet名2', 'topics': [{'title': '模块3', 'topics': [{'title': '功能5', 'topics': [{'title': '测试点9', 'topics': [{'title': '预置条件13', 'topics': [{'title': '测试步骤13', 'topics': [{'title': '预期结果13'}]}]}]}, {'title': '测试点10', 'topics': [{'title': '预置条件14', 'topics': [{'title': '测试步骤14', 'topics': [{'title': '预期结果14'}]}]}, {'title': '预置条件15', 'topics': [{'title': '测试步骤15', 'topics': [{'title': '预期结果15'}]}]}]}]}, {'title': '功能6', 'topics': [{'title': '测试点11', 'topics': [{'title': '预置条件16', 'topics': [{'title': '测试步骤16', 'topics': [{'title': '预期结果16'}]}]}]}, {'title': '测试点12', 'topics': [{'title': '预置条件17', 'topics': [{'title': '测试步骤17', 'topics': [{'title': '预期结果17'}]}]}, {'title': '预置条件18', 'topics': [{'title': '测试步骤18', 'topics': [{'title': '预期结果18'}]}]}]}]}]}, {'title': '模块4', 'topics': [{'title': '功能7', 'topics': [{'title': '测试点13', 'topics': [{'title': '预置条件19', 'topics': [{'title': '测试步骤19', 'topics': [{'title': '预期结果19'}]}]}]}, {'title': '测试点14', 'topics': [{'title': '预置条件20', 'topics': [{'title': '测试步骤20', 'topics': [{'title': '预期结果20'}]}]}, {'title': '预置条件21', 'topics': [{'title': '测试步骤21', 'topics': [{'title': '预期结果21'}]}]}]}]}, {'title': '功能8', 'topics': [{'title': '测试点15', 'topics': [{'title': '预置条件22', 'topics': [{'title': '测试步骤22', 'topics': [{'title': '预期结果22'}]}]}]}, {'title': '测试点16', 'topics': [{'title': '预置条件23', 'topics': [{'title': '测试步骤23', 'topics': [{'title': '预期结果23'}]}]}, {'title': '预置条件24', 'topics': [{'title': '测试步骤24', 'topics': [{'title': '预期结果24'}]}]}]}]}]}]}]}, 'structure': 'org.xmind.ui.logic.right'}]
  1. 循环获取字符串的代码为下面,最后可以得到最终循环的预置条件,测试步骤,预期结果等内容

FileName = jsonpath.jsonpath(ReadXmind[0],'$.topic.title')[0]
#print('FileName =',FileName)
FileNameList = jsonpath.jsonpath(ReadXmind[0],'$.topic.topics')[0]
#print(len(FileNameList),FileNameList)
for a in range(0,len(FileNameList)):SheetName = jsonpath.jsonpath(FileNameList[a],'$.title')[0]#print("SheetName =",SheetName)SheetNameList = jsonpath.jsonpath(FileNameList[a], '$.topics')[0]#print(len(SheetNameList), "SheetNameList =", SheetNameList[a])for b in range(0,len(SheetNameList)):ModuleList = SheetNameList[b]#print("ModuleList =",ModuleList)ModuleName = jsonpath.jsonpath(ModuleList,'$.title')[0]#print('ModuleName =',ModuleName)FunctionList = jsonpath.jsonpath(ModuleList,'$.topics')[0]#print('FunctionList =',FunctionList)for c in range(0,len(FunctionList)):TmpFunctionlist = FunctionList[c]FunctionName = jsonpath.jsonpath(TmpFunctionlist,'$.title')[0]TestPointList = jsonpath.jsonpath(TmpFunctionlist,'$.topics')[0]#print("FunctionName = %s,TestPoint = %s"%(FunctionName,TestPointList))for d in range(0,len(TestPointList)):TmpTestPoint = TestPointList[d]TestPointName = jsonpath.jsonpath(TmpTestPoint,'$.title')[0]TestList = jsonpath.jsonpath(TmpTestPoint,'$.topics')[0]#print("TestPointName = %s,TestList = %s"%(TestPointName,TestList) )for e in range(0,len(TestList)):TmpTestList = TestList[e]#print(TmpTestList)PresetConditions = jsonpath.jsonpath(TmpTestList,'$.title')[0]TestStep = jsonpath.jsonpath(TmpTestList,'$.topics[0].title')[0]ExpectedResults = jsonpath.jsonpath(TmpTestList,'$.topics[0].topics[0].title')[0]print('PresetConditions = %s,TestStep = %s,ExpectedResults = %s'%(PresetConditions,TestStep,ExpectedResults))

使用Python读取XMind格式测试用例,循环处理字符串相关推荐

  1. python用os.system打开wav文件_使用python读取wav格式文件

    ** 使用python读取wav格式文件 ** - 基本概念 [采样频率] 即取样频率, 指每秒钟取得声音样本的次数.采样频率越高,声音的质量也就越好,声音的还原也就越真实,但同时它占的资源比较多.由 ...

  2. python读取json格式的超参数

    python读取json格式的超参数 json文件: {"full_finetuning": true,"max_len": 180,"learnin ...

  3. python获取的html转换为json,python读取XML格式文件并转为json格式

    XML文件如下: 红楼梦书名> 曹雪芹作者> 描述贾宝玉和林黛玉的爱情故事主要内容> 人民文学出版社出版社> 图书> 一.python读取XML格式文件代码: impor ...

  4. RAW图像详解及使用Python读取raw格式图像并显示

    一.RAW图像详解 1.1 什么是raw格式图像? RAW在英文中的解释是未处理的.自然状态的,这也就是RAW文件的真谛.RAW图像就是CMOS或者CCD图像感应器将捕捉到 的光源信号转化为数字信号的 ...

  5. 使用Python读取raw格式图像并显示

    整理日期:2020-02-13 整理内容:使用Python读取raw格式图像并显示 代码如下: import cv2 #OpenCV包 import numpy as np# 首先确定原图片的基本信息 ...

  6. python读取webp格式图像

    使用python读取webp格式图像 from PIL import Imageimport pdb;pdb.set_trace() filename = '000.webp' im = Image. ...

  7. python读取 .trs 格式等特殊文本文件

    python读取 .trs 格式等特殊文本文件 1.前言 .trs文件是拓尔思bai(trs)公司异构文本检索的类似"du脚本"的文件,带有数据库的简单描述内容. trs格式文件在 ...

  8. python读取各种格式文件方式

    python读取各种格式文件方式 1.读取图片并显示 #方法1 from PIL import Image img=Image.open('1.jpg') img.show() #方法2 import ...

  9. python读取特殊格式文件

    python读取特殊格式文件 1.pytorch读取lmdb格式文件 参考文献 做深度学习/数据分析,数据读取是基础.必需的一环.特整理,以待后用. 1.pytorch读取lmdb格式文件 内容来源于 ...

最新文章

  1. python制作excel表格-excel表格中怎么制作一份燃尽图表
  2. Spring@Autowired注解
  3. c语言二进制数怎么表示_搞懂这些公式和原理,二级C语言对你来说肯定会简单很多!...
  4. Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来...
  5. ubuntu linux固定ip设置,Ubuntu 配置静态IP
  6. 中国焦磷酸四钾市场趋势报告、技术动态创新及市场预测
  7. 使用 Commander 写自己的 Nodejs 命令
  8. Takeown 实现解析
  9. Ubuntu8.04安置XCrysDen
  10. 字符串中索引位置是什么意思_女孩子左手中指戴戒指什么意思 不同位置各有不同...
  11. 小程序加入人脸识别_微信小程序怎么实现人脸识别
  12. wifi分析仪怎么看哪个信道好_WiFi信道扫描仪:通过NetSpot选择最佳WiFi信道
  13. 编译原理教程_2 文法和语言
  14. 运营商线路细分_国内三大运营商宽带线路及分级介绍
  15. 杭电多校(MINIEYE)第四场 补题
  16. 前端页面缓存系列之localStorage
  17. 图文并茂教你怎么制作pdf文件的目录?
  18. 【selenium】窗口操作
  19. rollup打包工具
  20. node如何使用mongoose?

热门文章

  1. SLIC与目前最优超像素算法的比较 SLIC Superpixels Compared to State-of-the-art Superpixel Methods
  2. 51单片机:HCSR04超声波测距模块及1602显示—C51程序(超详细)
  3. 【SwiftUI模块】0007、SwiftUI新手指引-新手指示-聚光灯介绍说明
  4. MyEclipse 下载与安装
  5. python数据爬取、分析与内容审核基于PaddlePaddle
  6. Excel 数据透视表教程大全之 04 按日期分组(教程含样本数据)
  7. 基金疯魔,硬汉落泪!用Python看破藏在盈损动态里的道道儿
  8. 《钢铁是怎样炼成的》的读后感作文5000字
  9. 二叉树已知前序遍历、中序遍历画出二叉树的形状
  10. 超人气代码格式化工具prettier