python 将xmind用例转换为excel用例
2021/11/8 22:13:15
本文主要是介绍python 将xmind用例转换为excel用例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# -*- coding: utf-8 -*- from xmindparser import xmind_to_dict import xlwt # 记录列数,全局变量,还原方便 columnIndex = 0 # 记录行数 rowIndex = 1 # 每个完整用例子主题的个数 caseCount = 0 def get_xmind_zen_dict(ws, main_topic): """ ws:工作表 main_topic:主功能点 """ # 获取功能模块个数 feature_topic_count = len(case_topics_count) global rowIndex global columnIndex global caseCount title_list = ['用例目录', '用例名称', '前提条件', '操作步骤', '期望结果'] # 用例标题写入excel首行 for j in range(0, len(title_list)): ws.write(0, j, title_list[j]) j += 1 # 比对功能点,并写入固定列 for index in range(0, feature_topic_count): # 当前层级主题的标题 topic_title = case_topics_count[index]['title'] # 将已经提取出来的外层主题进行对比,设置为最外层的用例名 if topic_title in main_topic: columnIndex = 1 # 设置功能点key到固定列 # 将功能点写入固定列 ws.write(rowIndex, columnIndex, topic_title) if 'topics' in case_topics_count[index].keys(): # 开始读取功能用例,并记录用例个数 caseCount += 1 topic_topics = case_topics_count[index]['topics'] # 获取用例步骤 # 写前提条件 if 'topics' in topic_topics[0]: qianti_topics = topic_topics[0]['topics'] qianti_topics_j = [] for title in qianti_topics: qianti_topics = title['title'].encode('utf-8') # unicode编码转str qianti_topics_j.append(qianti_topics) # 追加内容 qianti = "\n".join([str(e) for e in qianti_topics_j]) # 拼接并换行 ws.write(rowIndex, columnIndex + 1, qianti) # 写步骤 step_topics = topic_topics[1]['topics'] #print(type(step_topics)) step_topics_j = [] for title in step_topics: step_topics = title['title'].encode('utf-8') #print('=====') step_topics_j.append(step_topics) #print(step_topics_j) step = "\n".join([str(e) for e in step_topics_j]) # 拼接多个步骤并换行 ws.write(rowIndex, columnIndex + 2, step) #print('===步骤==') # 写预期结果 yuqi_topics = topic_topics[2]['topics'] yuqi_topics_j = [] for title in yuqi_topics: yuqi_topics = title['title'].encode('utf-8') #print(yuqi_topics) yuqi_topics_j.append(yuqi_topics) yuqi = "\n".join([str(e) for e in yuqi_topics_j]) ws.write(rowIndex, columnIndex + 3, yuqi) rowIndex += 1 # 写系统版本,功能模块 system_version = 'IoT Platform 2.1-系统管理优化' for i in range(0, caseCount): ws.write(i+1, 0, system_version) print('用例总数%s:' % caseCount) if __name__ == '__main__': # 用例地址 file_path = 'Iot Platform V2.1系统管理优化用例.xmind' #file_path = 'Iot platform.xmind' save_file = 'export.xlsx' # 首层画布 xmind_origin = xmind_to_dict(file_path) #print('+++画布所有内容+++') #print(xmind_origin) # 用例标题 case_title = xmind_origin[0]['topic']['title'] #print('--取出用例标题---') #print(case_title) # 主用例 case_topics = xmind_origin[0]['topic']['topics'] #print('---取出各模块用例--') #print(case_topics) # 取出单个模块的功能用例 case_topics_count = case_topics[0]['topics'] #print('---取出单个模块的功能用例点--') #print(case_topics_count) # 需要把功能点title记录下来,以便进行匹配 main_topic = [] for topic in case_topics_count: main_topic.append(topic['title']) #print('==取出功能点title==') #print(main_topic) # 使用xlwt模块 wb = xlwt.Workbook(encoding='utf-8') ws = wb.add_sheet('Test', cell_overwrite_ok=True) # 用例集遍历 get_xmind_zen_dict(ws, main_topic) # 保存Excel文档 wb.save('export.xls')
这篇关于python 将xmind用例转换为excel用例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python