生活随笔
收集整理的这篇文章主要介绍了
xmind转excel脚本(简化版)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
xmind转excel(简化版)由于测试过程中需要编写用例点和测试用例,每次都是测试点写完,还得将测试点复制到excel中,基于这种前提下,写了个简化版的xmind工具
思路
1.获取xmind中数据,调用“xmind_to_dict”方法获取到dict类型的xmind数据
2.通过dict的操作获取到从测试点数据,并封装成list,其中严重性和预期结果相同
3.在通过openpyxl库,调用“cell"方法,根据指定列去写入数据(其中由于用例模板中严重性是字母表示,而xmind中获取的是阿拉伯数字,所以严重在写入时要进行一次转换)
二、使用步骤
1.使用的库
openpyxl
xmindparser
import openpyxl as openpyxl
from xmindparser import xmind_to_dict
#设置excel列和严重性全局变量global title_excel
title_excel = {'A':1,'C':3,'D':4,'G':7}
global Priority
Priority = {1:'A',2:'B',3:'C',4:'D'}class xmindParserTool():def __init__(self,xmind_path):self.xmind_path = xmind_pathself.topics = xmind_to_dict(self.xmind_path)[0]['topic']#获取数据一级节点def getOneTopics(self):topics = self.topics.get('topics')return topics#获取测试点@propertydef testPoint(self):one_topics = self.getOneTopics()title =[]for j in range(len(one_topics)):topic =one_topics[j].get('topics')for i in range(len(topic)):if topic[i]['title'] !=None:title.append(topic[i]['title'])else:title.append('无测试点')return title#获取严重等级数据@propertydef getPriority(self):one_topics = self.getOneTopics()priority = []for j in range(len(one_topics)):topic = one_topics[j].get('topics')for i in range(len(topic)):# 截取字符串,获取严重等级priority_data = topic[i].get('makers')if priority_data !=None:priority_split = priority_data[0].split('-')priority.append(priority_split[1])else:priority.append('4')return priority#获取用例预期结果数据@propertydef expectedResults(self):one_topics = self.getOneTopics()title =[]for i in range(len(one_topics)):expected_topics = one_topics[i]['topics']for j in range(len(expected_topics)):try:expected_topics_inner = expected_topics[j]['topics']except KeyError:title.append('无预期结果')else:for k in range(len(expected_topics_inner)):title.append(expected_topics_inner[k]['title'])return title# if __name__ == '__main__':
# xx = xmindParserTool(r'C:\Users\Administrator\Desktop\自动化平台需求-V4.4-登录信息作用域改造.xmind')
# print(xx.getPriority)class writeToExcel(xmindParserTool):def __init__(self, xmind_path,excel_path):self.xmind = xmindParserTool(xmind_path)self.path = excel_pathself.excel = openpyxl.load_workbook(self.path)self.active = self.excel.worksheets[0]#指定列列,逐行写入数据def writeData(self):#测试点数据gTT_data=self.xmind.testPoint#预期结果gFT_data=self.xmind.expectedResults#严重等级gP_data=self.xmind.getPriorityfor i in range(len(gTT_data)):for j in range(len(gTT_data[i])):self.active.cell(row=i + 2, column=title_excel.get('A')).value = gTT_data[i]for i in range(len(gFT_data)):for j in range(len(gFT_data[i])):self.active.cell(row=i + 2, column=title_excel.get('C')).value = gFT_data[i]for i in range(len(gP_data)):self.active.cell(row=i + 2, column=title_excel.get('D')).value = Priority.get(int(gP_data[i]))if Priority.get(int(gP_data[i])) == 'A':self.active.cell(row=i + 2, column=title_excel.get('G')).value = '是'self.excel.save(self.path)if __name__ == '__main__':
#在xmind和excel的format中输入对应文件名xmind = r'C:\Users\Administrator\Desktop\{0}.xmind'.format('xmind_name')excel = r'C:\Users\Administrator\Desktop\{0}.xlsx'.format('excel_name')ww = writeToExcel(xmind,excel)ww.writeData()
总结
1.python初级小白,代码写的比较low,大神们看看就好,主要是记录下自己学习过程中的成果,轻喷。
2.通过这个脚本也一定程度减轻了自己日常工作的重复性劳作,提升了自己效率,
总结
以上是生活随笔为你收集整理的xmind转excel脚本(简化版)的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。