網站首頁 編程語言 正文
1、Xmind用例編寫規范
- 1:需求大模塊
- 2:大模塊中的小模塊(需要根據需求來看需要多少層)
- 3:用例等級和用例名稱
- 用例等級(轉換成Excel文件后,1為High, 2 為 Middle, 3為Low)
- 轉換成excel時,用例的名稱為(框出來的1-2-3組合而成),意味著在標等級及之前的節點會組合成用例名稱
- 4:步驟
- 5:期望結果
- 6:預置條件,轉換成excel時相同層級下的用例會為同一個預置條件
2、轉換代碼
需要安裝python3環境
需要安裝 xlwt、xmindparser 這兩個第三方包
XmindExcel.py 文件代碼
# coding=utf-8
import time
import xlwt
from past.builtins import raw_input
from xmindparser import xmind_to_dict
def resolvePath(dict, lists, title):
? ? # title去除首尾空格
? ? title = title.strip()
? ? # 如果title是空字符串,則直接獲取value
? ? if len(title) == 0:
? ? ? ? concatTitle = dict['title'].strip()
? ? elif "makers" in dict.keys():
? ? ? ? if "priority-" in str(dict["makers"]):
? ? ? ? ? ? concatTitle = title + '\t' + dict['title'].strip() + "\t" + str(dict["makers"])
? ? ? ? else:
? ? ? ? ? ? concatTitle = title + '\t' + dict['title'].strip()
? ? else:
? ? ? ? concatTitle = title + '\t' + 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, groupname):
? ? f = xlwt.Workbook()
? ? sheet = f.add_sheet(groupname, cell_overwrite_ok=True)
? ? row0 = ["測試用例編號", "用例標題", "預置條件", "執行方式", "優先級", "測試步驟", "預期結果", "所屬項目"]
? ? # 生成第一行中固定表頭內容
? ? for i in range(0, len(row0)):
? ? ? ? sheet.write(0, i, row0[i])
? ? # 增量索引
? ? index = 0
? ? # case級別
? ? case_leve_index = ""
? ? # 前置條件
? ? case_pre_condition = []
? ? pre_num = 0
? ? for h in range(0, len(list)):
? ? ? ? # print("list:",list)
? ? ? ? lists = []
? ? ? ? resolvePath(list[h], lists, '')
? ? ? ? for j in range(0, len(lists)):
? ? ? ? ? ? # 將xmind轉成excel
? ? ? ? ? ? lists[j] = lists[j].split('\t')
? ? ? ? ? ? try:
? ? ? ? ? ? ? ? # print(index)
? ? ? ? ? ? ? ? if "【預置條件】" in lists[j][-1] or "【前置條件】" in lists[j][-1]:
? ? ? ? ? ? ? ? ? ? case_pre_condition.append(lists[j])
? ? ? ? ? ? ? ? ? ? pre_num += 1
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? case_leve = ""
? ? ? ? ? ? ? ? ? ? for n in range(len(lists[j])):
? ? ? ? ? ? ? ? ? ? ? ? if 'priority-' in str(lists[j][n]):
? ? ? ? ? ? ? ? ? ? ? ? ? ? case_leve_index = n-1
? ? ? ? ? ? ? ? ? ? ? ? ? ? if "priority-1" in str(lists[j][n]):
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case_leve = "High"
? ? ? ? ? ? ? ? ? ? ? ? ? ? elif "priority-2" in str(lists[j][n]):
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case_leve = "Middle"
? ? ? ? ? ? ? ? ? ? ? ? ? ? elif "priority-3" in str(lists[j][n]):
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case_leve = "Low"
? ? ? ? ? ? ? ? ? ? ? ? ? ? lists[j].pop(n)
? ? ? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? ? ? case_name = "-".join(lists[j][:case_leve_index+1])
? ? ? ? ? ? ? ? ? ? sheet.write(j + index + 1 - pre_num, 1, case_name) ?# 標題
? ? ? ? ? ? ? ? ? ? if len(lists[j][case_leve_index:-1]) < 2:
? ? ? ? ? ? ? ? ? ? ? ? sheet.write(j + index + 1 - pre_num, 6, lists[j][case_leve_index + 1]) ? # 期望結果
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? sheet.write(j + index + 1- pre_num, 5, lists[j][case_leve_index + 1]) ?# 步驟
? ? ? ? ? ? ? ? ? ? ? ? sheet.write(j + index + 1- pre_num, 6, lists[j][case_leve_index + 2]) ?# 期望結果
? ? ? ? ? ? ? ? ? ? sheet.write(j + index + 1- pre_num, 3, "手動") ?# 執行方式
? ? ? ? ? ? ? ? ? ? sheet.write(j + index + 1 - pre_num, 4, case_leve)
? ? ? ? ? ? ? ? ? ? # 預置條件
? ? ? ? ? ? ? ? ? ? if len(case_pre_condition) > 0:
? ? ? ? ? ? ? ? ? ? ? ? for pre_list in case_pre_condition:
? ? ? ? ? ? ? ? ? ? ? ? ? ? if set(pre_list[:-1]) < set(lists[j]):
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sheet.write(j + index + 1 - pre_num, 2, pre_list[-1])
? ? ? ? ? ? except:
? ? ? ? ? ? ? ? print("請檢查編寫的用例是否符合規范:", lists[j])
? ? ? ? ? ? # 遍歷結束lists,給增量索引賦值,跳出for j循環,開始for h循環
? ? ? ? ? ? if j == len(lists) - 1:
? ? ? ? ? ? ? ? index += len(lists)
? ? ? ? f.save(excelname)
def maintest(filename, excelname):
? ? out = xmind_to_dict(filename)
? ? groupname = out[0]['topic']['title']
? ? xmind_cat(out[0]['topic']['topics'], excelname, groupname)
if __name__ == '__main__':
? ? try:
? ? ? ? path = raw_input("請輸入Xmind用例文件路徑,可將文件拖拽到此處:")
? ? ? ? filename = path
? ? ? ? excelname = path.rstrip('xmind') + 'xls'
? ? ? ? maintest(filename, excelname)
? ? ? ? print('SUCCESS!\n生成用例成功,用例目錄:%s' % excelname)
? ? except:
? ? ? ? print('請確認后重試:\n1.用例文件路徑中不能有空格換行符\n2.請使用python3運行\n3.檢查xmind文件中不能有亂碼或無法識別的字符(xmind自帶表情字符除外)\n4.檢查是否將已生成的excel文件未關閉')
3、使用
運行XmindExcel.py文件,輸入文件目錄運行即可。生成的Excel文件會在Xmind文件的同路徑下,文件名稱與Xmind文件名稱一致
原文鏈接:https://blog.csdn.net/sinat_18866031/article/details/125086436
相關推薦
- 2022-05-21 python實現會員信息管理系統(List)_python
- 2022-09-15 SQL?bool盲注和時間盲注詳解_MsSql
- 2022-11-18 關于python中第三方庫交叉編譯的問題_python
- 2022-08-05 記一次使用EasyExcel出現Convert excel format exception.You
- 2022-08-04 C#中ListView用法實例_C#教程
- 2023-08-13 uniapp寫一個隨時間變化的預約日期列表
- 2023-04-02 python導出requirements.txt的幾種方法總結_python
- 2022-04-02 C語言冒泡排序算法代碼詳解_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支