如何使用宏或 VbScript 使用 Excel 的“导出到 HP ALM”插件
Posted
技术标签:
【中文标题】如何使用宏或 VbScript 使用 Excel 的“导出到 HP ALM”插件【英文标题】:How to use 'Export to HP ALM' Addin for Excel using Macro or VbScript 【发布时间】:2018-01-30 13:09:06 【问题描述】:我正在尝试找到一种方法来自动将 excel 中的手动测试用例上传到 ALM。我一直在使用“导出到 HP ALM”插件。但是,此过程是手动的,因为您需要选择范围并按照此插件的向导之类步骤进行操作。
是否可以通过 Macro/vbscript 使用此插件?或者有什么方法可以通过 OTA 使用此插件中使用的相同地图名称?
更新 1:
找到了解决上述问题的方法(答案发布在下面)但是,我需要加快处理速度,即减少上传所需的时间。有什么帮助吗?
【问题讨论】:
简单的答案是肯定的。网络上有很多这样的例子。请进行研究,尝试一下,如果您的代码有问题,我们可以帮助解决问题 嗨 Zac,我尝试在宏中以传统方式使用它,但没有用 - 这个 Addin(.xla) 受密码保护,我可以进一步利用它的方法 - 还有我的例子网上遇到的都差远了。我可以在这里找到一个方向 试试***.com/questions/32055587/…。这不完全是您所需要的,但您应该能够开始 @Zac - 谢谢,我能够根据您之前的示例制定解决方案。看看它。它工作正常,但我希望有帮助来加快它。有什么想法吗? 【参考方案1】:给你:
Sub QCUpload()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim Cell As Range
Dim sBook As String
If Workbooks.Count < 2 Then
MsgBox "Error: Only one Workbook is open" & vbCr & _
"Open a 2nd Workbook and run this macro again."
Exit Sub
End If
'target work book
Set wb1 = ThisWorkbook
For Each wb2 In Workbooks
If wb2.Name <> wb1.Name Then Exit For
Next
MsgBox "1. - " & wb1.Name
MsgBox "2. - " & wb2.Name
FolderValue = wb1.Worksheets(1).Cells(11, 1)
' get the count of worksheet
MsgBox "Total Worksheet in " & wb2.Name & " is " & wb2.Worksheets.Count
' Verify if the field names are correct
For i = 1 To wb2.Worksheets.Count
For J = 1 To wb2.Worksheets(i).UsedRange.Columns.Count - 1
If Not wb2.Worksheets(i).Cells(1, J) = wb1.Worksheets(1).Cells(9, J) Then
MsgBox "Column Names are not proper"
Err = 1
Exit For
End If
Next
'Check for special characters
nLR = wb2.Worksheets(i).Cells.SpecialCells(xlCellTypeLastCell).Row
For cw = 2 To 6
If wb1.Worksheets(1).Cells(8, cw) <> "" Then
RpVal = wb1.Worksheets(1).Cells(8, cw)
wb2.Worksheets(i).Columns("C").Replace What:=RpVal, _
Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False
End If
Next
Next
'Check for any errors
If Err = 1 Then
MsgBox "There are error"
Exit Sub
End If
'Connect to ALM
Set TDConn = CreateObject("TDApiOle80.TDConnection")
'QC Connection data
login_id = wb1.Worksheets(1).Cells(3, 2).Value
login_passwd = wb1.Worksheets(1).Cells(4, 2).Value
domain_name = wb1.Worksheets(1).Cells(5, 2).Value
project_name = wb1.Worksheets(1).Cells(6, 2).Value
server_name = wb1.Worksheets(1).Cells(7, 2).Value
TDConn.InitConnectionEx server_name
TDConn.login login_id, login_passwd
TDConn.Connect domain_name, project_name
'' set root folder
Set tsf = TDConn.TestFactory
Set trmgr = TDConn.TreeManager
Set subjectfldr = trmgr.NodebyPath("Subject")
' read the main and sub folder names
Set subjectfldr = trmgr.NodebyPath(FolderValue)
subjectfldr.Post
'
' Iterate through all testcases on a sheet
For i = 1 To wb2.Worksheets.Count
LastRow = wb2.Worksheets(i).Cells.SpecialCells(xlCellTypeLastCell).Row
For CurrRow = 2 To LastRow
'Test case no:
If wb2.Worksheets(i).Cells(CurrRow, 2) <> "" Then
TestCaseNo = wb2.Worksheets(i).Cells(CurrRow, 2)
' now create a test case
Set MyTest = subjectfldr.TestFactory.AddItem(Null)
' set mandatory values
MyTest.Field("TS_NAME") = wb2.Worksheets(i).Cells(CurrRow, 3)
MyTest.Field("TS_USER_03") = wb2.Worksheets(i).Cells(CurrRow, 8) ' Complexity
MyTest.Field("TS_TYPE") = wb2.Worksheets(i).Cells(CurrRow, 9) ' Functionality
MyTest.Post
' create test steps
Set dsf = MyTest.DesignStepFactory
' loop through all the steps
For RowCount = CurrRow To LastRow
If wb2.Worksheets(i).Cells(RowCount, 4) = "" Then
Exit For
Else
Set dstep = dsf.AddItem(Null)
dstep.StepName = wb2.Worksheets(i).Cells(RowCount, 5)
dstep.StepDescription = wb2.Worksheets(i).Cells(RowCount, 6)
dstep.StepExpectedResult = wb2.Worksheets(i).Cells(RowCount, 7)
dstep.Post
End If
Next
End If
Next
Next
'End Upload
MsgBox "Upload Complete"
' Diconnect TD connection
TDConn.Disconnect
' Log the user off the server
TDConn.Logout
'Release the TDConnection object.
TDConn.ReleaseConnection
' Release the object
Set TDConn = Nothing
End Sub
【讨论】:
您可以采取一些措施来加快速度。说了这么多,你觉得跑慢的原因是什么?另外,从您的代码来看,在您与 ALM 建立连接之前,我并不完全了解您想要实现的目标 好吧,我无法指出缓慢的根本原因。上传大约 20 个测试用例(大约 85 行)大约需要 45-50 秒。也许这是进行 Excel-ALM 集成的最佳时间?我不知道,但如果有任何方法可以加快速度,我会喜欢的。 -“ALM 连接”之前的代码仅用于 Excel 表(测试用例所在的位置),用于安排/检查每列的重复/非法数据,并在“测试名称”中使用时替换任何受限字符基本上用户应该打开他们的测试用例表并运行这个宏以上是关于如何使用宏或 VbScript 使用 Excel 的“导出到 HP ALM”插件的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 VBSCript 在 Excel 中查找合并单元格的开始行和结束行?