您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源測(cè)試管理工具 > Testlink
TestLink測(cè)試用例Excel轉(zhuǎn)換XML工具
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2015/6/2 14:43:30 ] 推薦標(biāo)簽:測(cè)試管理工具

  TestLink對(duì)于測(cè)試用例的管理來說,是蠻強(qiáng)大的,但是在導(dǎo)入導(dǎo)出這塊,功能有點(diǎn)弱,本文針對(duì)測(cè)試用例的導(dǎo)入,轉(zhuǎn)載了一個(gè)Excel轉(zhuǎn)換成xml工具。
  1、根據(jù)到處的測(cè)試用例xml,定義一下我的Excel的格式如下:

  2、如果還沒有開始寫用例的,可以一依據(jù)這個(gè)模板,在excel中編寫用例,以下腳本是按照單元格的順序讀取的,所以這里的格式要調(diào)整,腳本中也要做相應(yīng)的調(diào)整。
Dim objexcel,objworkbook,objsheet,objxml_inter,objxml,totalrow,row,id,excelStr
'========================================
'創(chuàng)建Excel對(duì)象,關(guān)閉Excel對(duì)象--函數(shù)
'=========================================
Function getExcel(excelname, excelpath)
Set objexcel = CreateObject("excel.application")
Set objworkbook = objexcel.Workbooks.Open(excelpath)
Set objsheet = objworkbook.Sheets(excelname)
End Function
Function clsExcel()
objworkbook.Close
End Function
'============================================
Function dealStr(excelStr)
For id=2 To 8
excelStr = Replace(excelStr,id&"、","<br/>"&id&"、")
excelStr = Replace(excelStr,id&".","<br/>"&id&".")
Next
dealStr=excelStr
End Function
'========================
'獲取Excel單元格數(shù)據(jù),并將XML的格式寫入到對(duì)應(yīng)的單元格,之后通過創(chuàng)建XML對(duì)象生成XML文件
'========================
Function getExcelData()
row=2
objxml_inter=""
Do While Not (objsheet.cells(row,2).value="")
'internalid
objxml_inter=objxml_inter&CStr("<testcase internalid=""")  '
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,1))) '內(nèi)部用例編號(hào)
objxml_inter=objxml_inter&CStr(""" name=""")
'caseName
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,2))) '用例名稱
objxml_inter=objxml_inter&CStr(""">")
objxml_inter=objxml_inter&CStr("<node_order><![CDATA[0]]></node_order>")
'externalid
objxml_inter=objxml_inter&CStr("<externalid><![CDATA[")
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,1))) '外部用例編號(hào)
objxml_inter=objxml_inter&CStr("]]></externalid>")
'summary
objxml_inter=objxml_inter&CStr("<summary><![CDATA[<p>")
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,3))) '摘要
objxml_inter=objxml_inter&CStr("</p>]]></summary>")
'preconditions
objxml_inter=objxml_inter&CStr("<preconditions><![CDATA[<p>")
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,6))) '前置條件
objxml_inter=objxml_inter&CStr("</p>]]></preconditions>")
'execution_type
objxml_inter=objxml_inter&CStr("<execution_type><![CDATA[")
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,5))) '執(zhí)行方式:手工1,自動(dòng)的2
objxml_inter=objxml_inter&CStr("]]></execution_type>")
'importance
'objxml_inter=objxml_inter&CStr("<importance><![CDATA[1]]></importance>")
objxml_inter=objxml_inter&CStr("<importance><![CDATA[")
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,4))) '重要性:高3中2低1
objxml_inter=objxml_inter&CStr("]]></importance>")
'steps
objxml_inter=objxml_inter&CStr("<steps>")
'step
objxml_inter=objxml_inter&CStr("<step>")
'step_number
objxml_inter=objxml_inter&CStr("<step_number><![CDATA[1]]></step_number>")
'action
objxml_inter=objxml_inter&CStr("<actions><![CDATA[<p>")
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,7))) '測(cè)試步驟
objxml_inter=objxml_inter&CStr("</p>]]></actions>")
'expectedresults
objxml_inter=objxml_inter&CStr("<expectedresults><![CDATA[<p>")
objxml_inter=objxml_inter&CStr(dealStr(objsheet.cells(row,8))) '預(yù)期結(jié)果
objxml_inter=objxml_inter&CStr("</p>]]></expectedresults>")
'execution_type
objxml_inter=objxml_inter&CStr("<execution_type><![CDATA[1]]></execution_type>")
objxml_inter=objxml_inter&CStr("</step>")
objxml_inter=objxml_inter&CStr("</steps>")
objxml_inter=objxml_inter&CStr("</testcase>")
'CStr(objsheet.cells(x,1)),CStr(objsheet.cells(x,2))
'MyFile.Write(objxml_inter)
'WScript.Echo x-1
row=row+1
Loop
totalrow = row-2
End Function
'========================
'創(chuàng)建XML文件
'========================
Sub CreateXML
Dim fileObj, XmlFile
Set fileObj = CreateObject("Scripting.FileSystemObject")
Set XmlFile = fileObj.CreateTextFile(XMLname, True)
'xml title
objxml=CStr("<?xml version=""1.0"" encoding=""GBK""?>")
objxml=objxml&CStr("<testcases>")
objxml=objxml&objxml_inter
objxml=objxml&CStr("</testcases>")
XmlFile.Write(objxml)
XmlFile.Close
End Sub
excelpath = InputBox("請(qǐng)輸入Excel文件正確的路徑名和文件名:","TestLink 1.9.13小助手: Excel轉(zhuǎn)換XML工具")
If excelpath = "" Then
MsgBox "文件名不能為空!"
WScript.Quit
ElseIf InStr(excelpath,".xls") < 1 Then
MsgBox "文件名格式不對(duì)!"
WScript.Quit
End    If
excelname = InputBox("請(qǐng)輸入Excel中所要操作的表格名稱:","TestLink 1.9.13小助手: Excel轉(zhuǎn)換XML工具")
If excelname = "" Then
MsgBox "文件名不能為空!"
WScript.Quit
End If
XMLname = InputBox("請(qǐng)輸入轉(zhuǎn)換之后的XML文件保存路徑和名稱:","TestLink 1.9.13小助手: Excel轉(zhuǎn)換XML工具")
If XMLname = "" Then
MsgBox "文件名不能為空!"
WScript.Quit
ElseIf    InStr(XMLname,".xml") < 1 Then
MsgBox "文件名格式不對(duì)!"
WScript.Quit
End    If
'初始化excel對(duì)象
Call getExcel(excelname, excelpath)
'讀入Excel數(shù)據(jù)
Call getExcelData()
'寫入數(shù)據(jù), XML
CreateXML
'關(guān)閉Excel對(duì)象
Call clsExcel()
'提示信息
  MsgBox "完成從Excel到XML的數(shù)據(jù)轉(zhuǎn)換,總共"+CStr(totalrow)+"條!"
  腳本保存本地,選擇編碼方式為unicode,后綴名為.vbs
  注意:excel表中的用例編號(hào)是不能相同的,應(yīng)該是的
  遺留問題:有多行步驟的時(shí)候,只能生成一行,即三個(gè)actions和expectresult,這個(gè)只能生成一個(gè)

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd