HP ALM 11.52 - OTA API - 使用 VB 脚本签入/签出测试用例

Posted

技术标签:

【中文标题】HP ALM 11.52 - OTA API - 使用 VB 脚本签入/签出测试用例【英文标题】:HP ALM 11.52 - OTA API - Check In/Out test cases with VB script 【发布时间】:2015-10-15 08:45:56 【问题描述】:

我正在使用 OTA 将测试用例从 excel 上传到 ALM。

我使用了excel插件,发现它对于我的项目需求来说相当麻烦,所以我正在编写一个自定义脚本来完成任务。

注意:版本控制已开启。

我有版本控制,因此,我需要先检查创建的测试用例,然后才能添加步骤。最好,我希望能够在我完成后再次签入测试用例。有没有办法通过 OTA api 做到这一点?

这是我正在使用的脚本:

Sub UploadTC()

Dim QCConnection
Dim qcUserName, qcPassword, qcDomain, qcProj
Dim tsf, trmgr
Dim trfolder, trtest
Dim dsf, dstep, steplist
Dim TCR As Range
Dim cache As Range
Dim scount As Range
'Fields
Dim TCName As Range
Dim TCStep As Range
Dim TCDesc As Range
Dim TCExRe As Range
Dim TCComm As Range
Dim TCType As Range



'~~~These need to come from a user form. Temporary.
qcUserName = "ssoong01"
qcPassword = "*********"
qcDomain = "HUB"
qcProj = "*********"

Set QCConnection = CreateObject("TDApiOle80.TDConnection")
'MsgBox ("Connect to QC Server")

QCConnection.InitConnectionEx "http://hpalm-qc.*****.net:8080/qcbin/"
'MsgBox ("Connection Established.")

QCConnection.Login qcUserName, qcPassword
'MsgBox ("Login Authenticated.")

QCConnection.Connect qcDomain, qcProj
'MsgBox ("Connected to Project.")

Set tsf = QCConnection.TestFactory
Set trmgr = QCConnection.TreeManager

With ThisWorkbook.Sheets("Test Cases")

 'Create Project Folder
Set trfolder = trmgr.NodebyPath("Subject").AddNode(.Cells(3, 2))
trfolder.Post
'Loop through each row in sheet from A4
Set cache = ThisWorkbook.Sheets("Values").Range("$A$3")
For Each TCR In .Range(.Cells(4, 1), .Cells(.Cells(Rows.Count, 1).End(xlUp).Row, 1))
    Set TCName = .Range(TCR.Offset(0, 1).Address)
    Set TCType = .Range(TCR.Offset(0, 7).Address)

    'If Folder Then
        If TCType.Value = "Folder" Then
            Set trfolder = trmgr.NodebyPath("Subject" & TCR.Value).AddNode(TCName.Value)
            trfolder.Post
    'If Test Case Then
        ElseIf TCType.Value = "MANUAL" Then
            'If cached TC name = current row TC name then skip
            If TCName = cache.Value Then
            'Add Test Case
            ElseIf TCName <> cache.Value Then
                Set trfolder = trmgr.NodebyPath("Subject" & TCR.Value)
                Set trtest = trfolder.TestFactory.AddItem(TCName.Value)
                    ' set values
                    trtest.Field("TS_NAME") = TCName
                    trtest.Field("TS_RESPONSIBLE") = qcUserName ' Designer
                    trtest.Field("TS_TYPE") = "MANUAL"

                    trtest.Post

            'Steps
            Set dsf = trtest.DesignStepFactory
            Set steplist = dsf.Newlist("[empty]")

            ' loop through all the steps
            Set scount = .Range(TCName.Address)
            Do
                Set TCStep = .Range(scount.Offset(0, 1).Address)
                Set TCDesc = .Range(scount.Offset(0, 2).Address)
                Set TCExRe = .Range(scount.Offset(0, 3).Address)
                Set TCComm = .Range(scount.Offset(0, 4).Address)

                Set dstep = dsf.AddItem(Null)
                    dstep.Field("DS_STEP_NAME") = TCStep.Value
                    dstep.Field("DS_DESCRIPTION") = TCDesc.Value
                    dstep.Field("DS_EXPECTED") = TCExRe.Value
                    Set scount = .Range(scount.Offset(1).Address)
            Loop Until scount.Value <> scount.Offset(-1).Value

            dstep.Post

                'cache TC name
                cache.Value = TCName.Value
            End If
        Else:
            MsgBox ("Invalid type at cell: " & TCR.Address)
        End If

Next TCR

HP 应用程序生命周期管理

应用程序生命周期管理版 11.52.514

OTA 客户端 11.52.514.0

【问题讨论】:

【参考方案1】:

是的,您可以使用 OTA API 执行签入和签出操作。它在文档中进行了详细描述,并且那里还有一些示例脚本显示了它是如何完成的。我假设您知道在哪里可以找到 OTA API 参考/文档?

以下是文档中的示例脚本,它展示了如何编写一个执行测试签出的函数:

Public Function CheckoutTest(tst As Test, comment$, _
    ByRef CanContinue As Boolean) As Object

    On Error GoTo checkout_err
    CanContinue = True

    Dim fVersionControl As VCS
    Set fVersionControl = tst.VCS

    If IsNull(fVersionControl) Then
        Set CheckoutTest = Null
        Exit Function
    End If

    Set CheckoutTest = fVersionControl
    fVersionControl.CheckOut -1, comment, False

Exit Function
checkout_err:
    CanContinue = False
    ErrHandler err, "CheckoutTest", "", FATAL_ERROR
End Function

【讨论】:

【参考方案2】:

我在 OTA 文档中找到了我正在寻找的答案。绝对是我应该更频繁地利用的资源。

【讨论】:

以上是关于HP ALM 11.52 - OTA API - 使用 VB 脚本签入/签出测试用例的主要内容,如果未能解决你的问题,请参考以下文章

如何在 HP ALM 中更新测试运行的环境值

使用 ALM OTA,我们如何知道 ALM 资源是不是已签出?

如何通过 c# 将附件添加到 ALM OTA 中的测试集?

HP ALM

如何创建 C# OTA 代码以根据 ALM 中的测试计划中 Excel 中提供的路径创建文件夹。你能帮我解决这个问题吗?

HP ALM lis