Python xmind庫(生成框架圖)? 轉(zhuǎn)自??http://www.reibang.com/p/c4b1cc9486f2?from=timeline&isappinstalled=0
?
2018.04.03 18:16*?字數(shù) 152?閱讀 1242評論 5喜歡 9
小編在測試日常工作中遇到一個費時的問題构回,如何將excel中的測試用例澡屡,生成測試框架圖厘唾?經(jīng)過查閱發(fā)現(xiàn)的python xmind庫
將excel中的測試用例烤咧,生成測試框架圖屠阻,分為2步
1.解析excel炕贵,取出excel中數(shù)據(jù)(此部分暫時忽略)
2.將前一步準備的數(shù)據(jù)寫入 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':'搜索無結(jié)果'}]? ? ? creatXmindFile(data)
三亭引、生成的xmind
11_gaitubao_com_922x437.png