Python xmind库(生成框架图) 转自 https://www.jianshu.com/p/c4b1cc9486f2?from=timeline&isappinstalled=0
2018.04.03 18:16* 字数 152 阅读 1242评论 5喜欢 9
小编在测试日常工作中遇到一个费时的问题,如何将excel中的测试用例,生成测试框架图?经过查阅发现的python xmind库
将excel中的测试用例,生成测试框架图,分为2步
1.解析excel,取出excel中数据(此部分暂时忽略)
2.将前一步准备的数据写入 xmind(今天主要写此部分)
一、前提条件:
python xmind库安装(参考:https://link.zhihu.com/?target=https%3A//github.com/xmindltd/xmind-sdk-python)
二、代码部分:
#!/usr/bin/env python# -*- coding: utf-8 -*-importsys reload(sys) sys.setdefaultencoding('utf8')importxmindfromxmind.coreimportworkbook,saverfromxmind.core.topicimportTopicElementdefcreatXmindFile(data):module=[]foritemindata: module.append(item['module']) module=list(set(module)) w = xmind.load("test3.xmind")# load an existing file or create a new workbook if nothing is found s2=w.createSheet()# create a new sheets2.setTitle("框架") r2=s2.getRootTopic() r2.setTitle("框架")foriinrange(len(module)): t=TopicElement() t.setTitle(module[i]) r2.addSubTopic(t) w.addSheet(s2)# the second sheet is now added to the workbook r2_topics=r2.getSubTopics()# to loop on the subTopics fortopicinr2_topics: topic_name=topic.getTitle()printtopic_nameforitemindata:iftopic_name == item['module']: index=topic.getIndex() t=TopicElement() content=item['caseId']+" "+'\n'+item['summary'] t.setTitle(content) r2_topics[index].addSubTopic(t) summary=t.getTitle()foritemindata:ifitem['summary']insummary: t1=TopicElement() content1=item['name'] t1.setTitle(content1) t.addSubTopic(t1) xmind.save(w,"test3.xmind")# and we saveif__name__=='__main__': data=[{'name':'testClickTheMenuButton','caseId':'01','module':'书架','summary':'多次开启关闭书架', } , {'name':'testSearchWordWithoutResult','caseId':'02','module':'搜索','summary':'搜索无结果'}] creatXmindFile(data)
三、生成的xmind
11_gaitubao_com_922x437.png