python实现xmind_Python xmind库(生成框架图)

小编在测试日常工作中遇到一个费时的问题,如何将excel中的测试用例,生成测试框架图?经过查阅发现的python xmind库

将excel中的测试用例,生成测试框架图,分为2步

1.解析excel,取出excel中数据(此部分暂时忽略)

2.将前一步准备的数据写入 xmind(今天主要写此部分)

一、前提条件:

二、代码部分:

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import sys

reload(sys)

sys.setdefaultencoding('utf8')

import xmind

from xmind.core import workbook,saver

from xmind.core.topic import TopicElement

def creatXmindFile(data):

module=[]

for item in data:

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 sheet

s2.setTitle("框架")

r2=s2.getRootTopic()

r2.setTitle("框架")

for i in range(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

for topic in r2_topics:

topic_name=topic.getTitle()

print topic_name

for item in data:

if topic_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()

for item in data:

if item['summary'] in summary:

t1=TopicElement()

content1=item['name']

t1.setTitle(content1)

t.addSubTopic(t1)

xmind.save(w,"test3.xmind") # and we save

if __name__=='__main__':

data=[{

'name': 'testClickTheMenuButton',

'caseId': '01',

'module': '书架',

'summary': '多次开启关闭书架',

}

, {

'name': 'testSearchWordWithoutResult',

'caseId': '02',

'module': '搜索',

'summary': '搜索无结果'

}]

creatXmindFile(data)

三、生成的xmind

c4b1cc9486f2?from=timeline&isappinstalled=0

11_gaitubao_com_922x437.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值