用例xmind轉(zhuǎn)化excel

工作中常用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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末艺配,一起剝皮案震驚了整個(gè)濱河市察郁,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌转唉,老刑警劉巖皮钠,帶你破解...
    沈念sama閱讀 212,383評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異赠法,居然都是意外死亡麦轰,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,522評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén)砖织,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)款侵,“玉大人,你說(shuō)我怎么就攤上這事镶苞≡梗” “怎么了鞠评?”我有些...
    開(kāi)封第一講書(shū)人閱讀 157,852評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵茂蚓,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我剃幌,道長(zhǎng)聋涨,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,621評(píng)論 1 284
  • 正文 為了忘掉前任负乡,我火速辦了婚禮牍白,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘抖棘。我一直安慰自己茂腥,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,741評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布切省。 她就那樣靜靜地躺著最岗,像睡著了一般。 火紅的嫁衣襯著肌膚如雪朝捆。 梳的紋絲不亂的頭發(fā)上般渡,一...
    開(kāi)封第一講書(shū)人閱讀 49,929評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音芙盘,去河邊找鬼驯用。 笑死,一個(gè)胖子當(dāng)著我的面吹牛儒老,可吹牛的內(nèi)容都是我干的蝴乔。 我是一名探鬼主播,決...
    沈念sama閱讀 39,076評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼驮樊,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼淘这!你這毒婦竟也來(lái)了剥扣?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 37,803評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤铝穷,失蹤者是張志新(化名)和其女友劉穎钠怯,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體曙聂,經(jīng)...
    沈念sama閱讀 44,265評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡晦炊,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,582評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了宁脊。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片断国。...
    茶點(diǎn)故事閱讀 38,716評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖榆苞,靈堂內(nèi)的尸體忽然破棺而出稳衬,到底是詐尸還是另有隱情,我是刑警寧澤坐漏,帶...
    沈念sama閱讀 34,395評(píng)論 4 333
  • 正文 年R本政府宣布薄疚,位于F島的核電站,受9級(jí)特大地震影響赊琳,放射性物質(zhì)發(fā)生泄漏街夭。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,039評(píng)論 3 316
  • 文/蒙蒙 一躏筏、第九天 我趴在偏房一處隱蔽的房頂上張望板丽。 院中可真熱鬧,春花似錦趁尼、人聲如沸埃碱。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,798評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)砚殿。三九已至,卻和暖如春婶博,著一層夾襖步出監(jiān)牢的瞬間瓮具,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,027評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工凡人, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留名党,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,488評(píng)論 2 361
  • 正文 我出身青樓挠轴,卻偏偏與公主長(zhǎng)得像传睹,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子岸晦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,612評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容