使用 uft 创建 QC 资源

Create QC Resource with uft

我找到了很多关于通过 UFT 将资源上传到 ALM 的示例。 但是,始终有一个已在 ALM 中创建的资源。 我如何使用 UFT 创建资源并将其上传到 ALM? 我的问题是我不知道我需要多少资源,所以我必须动态创建资源然后上传它们。 我不想将文件作为附件上传到 运行。

谢谢

我想我在这里找到了答案:http://www.codetweet.com/other/create-new-resource-almqc-using-ota/

Sub CreateNewResource(resourceFolderId As Integer, fileType As String, fileName As String, fileParentFolderPath As String)

    On Error GoTo Errhandler:

    '--- Represents a file or folder stored in the Quality Center repository
    Dim resource As QCResource
    '--- Represents a QC resource folder.
    Dim resourceFolder As QCResourceFolder
    '--- Services for managing QC resources.
    Dim resourceFactory As QCResourceFactory
    '--- Services for managing QC resource folders.
    Dim resourceFolderFactory As QCResourceFolderFactory
    '--- Services to manage resource storage.
    Dim testResourceStorage As IResourceStorage
    Dim resourceItem
    Dim resourceFound As Boolean

    ' ***TDConn is TDConnection class object.Create this object before using this function.
    Set resourceFolderFactory = TDConn.QCResourceFolderFactory
    Set resourceFolder = resourceFolderFactory.Item(resourceFolderId)
    Set resourceFactory = resourceFolder.QCResourceFactory
    Set currResourceList = resourceFactory.NewList("")

    For ItemCount = 1 To currResourceList.Count
        currItem = currResourceList.Item(ItemCount).Name
        If UCase(currItem) = UCase(fileName) Then
            Set resourceItem = currResourceList.Item(ItemCount)
            resourceFound = True
            Exit For
        End If
    Next

   If Not resourceFound Then
        '--- Create a resource
        Set resourceItem = resourceFactory.AddItem(fileName)
        resourceItem.ResourceType = fileType
        resourceItem.fileName = fileName
        resourceItem.Post

        '--- Check if the resources added successfully
        Set currResourceList = resourceFactory.NewList("")
        For ItemCount = 1 To currResourceList.Count
            currItem = currResourceList.Item(ItemCount).Name
            If UCase(currItem) = UCase(fileName) Then
                resourceFound = True
                Exit For
            End If
        Next

        If resourceFound Then
            '--- Attach the file to resource
            resourceItem.vC.CheckOut ""
            Set testResourceStorage = resourceItem
            testResourceStorage.UploadResource fileParentFolderPath, False
            resourceItem.vC.CheckIn "Automated check-in by utility" & Now
        Else
             oFile.WriteLine ("Recently added new resource not found on ALM.Try again later.")
             Exit Sub
        End If
    Else
        resourceItem.vC.CheckOut ""
        Set testResourceStorage = resourceItem
        testResourceStorage.UploadResource fileParentFolderPath, False
        resourceItem.vC.CheckIn "Automated check-in by utility" & Now
    End If

    Set resourceFolderFactory = Nothing
    Set resourceFolder = Nothing
    Set resourceFactory = Nothing
    Set currResourceList = Nothing

    Exit Sub

Errhandler:
   MsgBox("Error Executing - `CreateNewResource`  ; Error Uploading file " & fileName)
   Exit Sub
End Sub