• 使用python把xmind文件转换为xlsx文件测试用例


    用例的格式可以自己修改

    import xlwt,xlrd
    from xmindparser import xmind_to_dict
    from openpyxl.styles import Font
    from openpyxl import load_workbook


    def resolvePath(dict,lists,title):
    # title去除首尾空格
    title = title.strip()
    # 如果title是空字符串,则直接获取value
    if len(title) == 0:
    concatTitle = dict['title'].strip()
    # print(concatTitle)
    else:
    concatTitle = title + ' ' + dict['title'].strip()

    if dict.__contains__('topics')==False:
    lists.append(concatTitle)
    else:
    for d in dict['topics']:
    resolvePath(d,lists,concatTitle)


    def xmind_cat(list,excelname):
    # print(f'list是{list}')
    # print(list)

    f = xlwt.Workbook()
    # 生成excel文件,单sheet,sheet名为:out1["title"]
    out1 = xmind_to_dict(filename)[0]["topic"]
    sheet = f.add_sheet(out1["title"] , cell_overwrite_ok=True)


    row0 = [ '用例标题','步骤','预期', '用例类型','使用阶段']
    # 生成第一行中固定表头内容
    for i in range(0, len(row0)):
    sheet.write(0, i, row0[i])

    # 增量索引
    index = 0

    for h in range(0,len(list)):
    lists = []
    resolvePath(list[h], lists, '')
    for j in range(0, len(lists)):
    # print(lists)

    lists[j] = lists[j].split(' ')

    for n in range(0, len(lists[j])):
    # print(lists[j][n])
    out1 = xmind_to_dict(filename)[0]["topic"]
    # 获取xmind的中心主题,拼接用例
    ii = out1["title"]+"-".join(lists[j])
    # print(lists[j])
    # 获取预期结果
    jj = lists[j][-1]
    # 写入表中
    sheet.write(j+index+1,0,ii)
    sheet.write(j+index+1,1,ii)
    sheet.write(j+index+1,2,jj)
    sheet.write(j+index+1,3,'功能测试')
    sheet.write(j+index+1,4,'系统测试阶段')


    # 遍历结束lists,给增量索引赋值,跳出for j循环,开始for h循环
    if j == len(lists) - 1:
    index += len(lists)

    f.save(excelname)

    def maintest( filename):
    out = xmind_to_dict(filename)
    excelname = filename.split('/')[-1].split('.')[0] + '.xlsx'
    xmind_cat(out[0]['topic']['topics'],excelname)
    # 获取文档的用例数
    filepath= excelname
    wb= xlrd.open_workbook(filepath)
    out1 = xmind_to_dict(filename)[0]["topic"]
    sheet1 =wb.sheet_by_name(out1["title"])
    n = sheet1.nrows-1
    print("用例数为:",n)


    if __name__ == '__main__':
    filename = 'xmind文件路径'
    maintest(filename)
  • 相关阅读:
    Inno Setup 6.0.4
    使用Microsoft Enterprise Library 5.0记录日志信息
    Log4net用法
    继续接着上一篇写:使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)[搜片神器]
    磁力王:种子磁力搜索神器使用教程
    C# WebBrowser 网页缩放的方法
    Mysql5.7修改root密码教程
    【MAVEN】maven项目下载更新pom jar包速度慢 解决方案
    C# DataGridView自动保存列的宽度和位置
    Java实现敏感词过滤
  • 原文地址:https://www.cnblogs.com/lldk/p/15207994.html
Copyright © 2020-2023  润新知