工作中常用xmind編寫(xiě)測(cè)試點(diǎn),項(xiàng)目用例平臺(tái)支持固定的模板導(dǎo)入,所以著手編寫(xiě)了一個(gè) xmind轉(zhuǎn)換 excel用例標(biāo)準(zhǔn)格式。
1.安裝 三方庫(kù)?xmindparser蹂安。
2.準(zhǔn)備了兩個(gè)文件,xmind_input.py 和 xmind_excel.py
xmind_excel.py锐帜,實(shí)現(xiàn) xmind 轉(zhuǎn)換為excel 田盈;xmind_input.py 通過(guò)三方庫(kù)PyQt5,實(shí)現(xiàn)了一個(gè)交互 缴阎。通過(guò)pyinstaller 三方庫(kù)允瞧,打包為一個(gè)可執(zhí)行工具,支持其他 window 上運(yùn)行蛮拔,打包中注意 需要完成 python 虛擬環(huán)境的搭建
PyQt5述暂,支持直接進(jìn)行xmind_input.ui文件,通過(guò) pyuic 轉(zhuǎn)換為?xmind_input.py建炫。做好前端交互
xmind_excel.py 文件編寫(xiě)最耗時(shí)畦韭,需要把xmind識(shí)別的 結(jié)果,每個(gè)字段的循環(huán)寫(xiě)入對(duì)應(yīng)excel 中肛跌。
代碼如下:
def xmind_ex(xmind_name,case_type,case_suit):
all_markets = ["priority-1", "priority-2", "priority-3"]
# xm = xmind_to_dict(xmind_name)[0]['topic']#讀取xmind 數(shù)據(jù)
? ? # xm = xmind_to_dict("/Users/jay/Code/work/xmid_excel/1119.xmind")[0]['topic']
? ? xm = xmind_to_dict(xmind_name)[0]['topic']
print(json.dumps(xm))
workbook = xlwt.Workbook(encoding='utf-8')#創(chuàng)建workbook對(duì)象
? ? worksheet = workbook.add_sheet(xm["title"], cell_overwrite_ok=True)#創(chuàng)建工作表 并設(shè)置可以重寫(xiě)單元格內(nèi)容
? ? row0 =["所屬模塊",'相關(guān)需求','用例標(biāo)題','前置條件','步驟','預(yù)期','優(yōu)先級(jí)','用例類(lèi)型','適用階段']# 寫(xiě)成excel表格用例的要素
? ? for iin range(len(row0)):
worksheet.write(0, i, row0[i])
x =0? # 寫(xiě)入數(shù)據(jù)的當(dāng)前行數(shù)
? ? z =0? # 用例的編號(hào)
? ? test_case =""
? ? test_suit =""
? ? for iin range(len(xm["topics"])):
test_module = xm["topics"][i]
# test_module['title'] = "denglu"
? ? ? ? markers_1 = test_module.get("makers")
if not markers_1and 'topics' in test_module:
for jin range(len(test_module["topics"])):
test_suit = test_module["topics"][j]
# test_suit['title'] = "ceshidian1"
? ? ? ? ? ? ? ? markers_2 = test_suit.get("makers")
print(markers_2)
if not markers_2and 'topics' in test_suit:
for kin range(len(test_suit["topics"])):
test_case = test_suit["topics"][k]
z +=1
? ? ? ? ? ? ? ? ? ? ? ? c1 =len(test_case["topics"])# 執(zhí)行步驟有幾個(gè)
? ? ? ? ? ? ? ? ? ? ? ? markers_3 = test_case.get("makers")
print(markers_3)
if not markers_3and 'topics' in test_case:
for nin range(len(test_case["topics"])):
test_step = test_case["topics"][n]
x +=1
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? test_except = test_step["topics"][0]
x1 =len(test_step["topics"])
markers_4 = test_step.get("makers")
print(markers_4)
b4=markers_4[len(markers_4)-1]
print(b4)
print(b4[len(b4)-1])
if not markers_4and 'topics' in test_step:
pass
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else:
for yin range(len(test_step["topics"])):
test_six = test_step["topics"][y]
test_x1 = test_six["topics"][0]
worksheet.write(x, 5, test_x1["title"])# 預(yù)期結(jié)果
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? print(markers_4[len(markers_4)-1])
# print(markers_4.split('-')[-1])
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # worksheet.write(x, 6, markers_4.split('-')[-1])? # 優(yōu)先級(jí)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 6, b4[len(b4)-1])# 優(yōu)先級(jí)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 7, case_type)# 用例類(lèi)型
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 8, case_suit)# 適用階段
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 4,? test_six["title"])# 預(yù)期結(jié)果
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 3, test_step["title"])# 執(zhí)行步驟----
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # worksheet.write_merge(x - c1 + 1, x, 0, 0, z)? # 所屬模塊
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write_merge(x - c1 +1, x, 0, 0, test_module["title"])#所屬模塊
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # worksheet.write_merge(x - c1 + 1, x, 1, 1, test_module["title"])? # 測(cè)試需求名稱(chēng)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write_merge(x - c1 +1, x, 2, 2,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? test_suit["title"] +"_" + test_case["title"])
else:
for nin range(len(test_case["topics"])):
b3 = markers_3[len(markers_3) -1]
test_step = test_case["topics"][n]
x +=1
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? test_except = test_step["topics"][0]
# worksheet.write(x, 6, markers_3.split('-')[-1])? #? 優(yōu)先級(jí)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 6,b3[len(b3)-1])# 優(yōu)先級(jí)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 7, case_type)# 用例類(lèi)型
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 8, case_suit)# 適用階段
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 5,? test_except["title"])# 預(yù)期結(jié)果
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write(x, 4,? test_step["title"])# 執(zhí)行步驟
? ? ? ? ? ? ? ? ? ? ? ? ? ? # worksheet.write_merge(x - c1 + 1, x, 0, 0, z)? # testcaseid
? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write_merge(x - c1 +1, x, 0, 0, test_module["title"])# 所屬模塊
? ? ? ? ? ? ? ? ? ? ? ? ? ? # worksheet.write_merge(x - c1 + 1, x, 1, 1, test_module["title"])? # 測(cè)試需求名稱(chēng)
? ? ? ? ? ? ? ? ? ? ? ? ? ? worksheet.write_merge(x - c1 +1, x, 2, 2, test_suit["title"])
worksheet.write_merge(x - c1 +1, x, 3, 3, test_case["title"])
time = get_time_stamp()
newname = xm["title"] + time +".xls"
? ? workbook.save(newname)# xls名稱(chēng)取xmind主題名稱(chēng)