Functions to download attachment from folder in Test Plan ALM

This function connects to QC test plan and gets the node of the folder you want the attachement from.

Public Function GetAttachmentFromFolder(FolderName, FileName, OutPath)
                Set TDConnection = QCUtil.TDConnection
                Set treeManager =  TDConnection.TreeManager
                Set node = treeManager.nodebypath(FolderName) 
                               
    GetAttachmentFromFolder = GetAttachmentFromTestObject(node, FileName, OutPath)
End Function

This function gets the attachment from the testobject which is extracted from the node which is extracted in above function

Public Function GetAttachmentFromTestObject (TestObject, FileName, OutPath)
                MyPath = GetAttachmentServerPath(TestObject, FileName, LongFileName)

                If StrComp(MyPath, "") = 0 Then
                                GetAttachment = ""
                                Exit Function
                End If

                If Right(OutPath, 1) <> "\" Then
                                OutPath = OutPath & "\"
                End If

                ' Load the attachment using the extended storage object
                Set TDConnection = QCUtil.TDConnection
                Set ExtendedStorage = TDConnection.ExtendedStorage
                ExtendedStorage.ServerPath = MyPath
                ExtendedStorage.ClientPath = OutPath
                ExtendedStorage.Load LongFileName, True
               
                GetAttachmentFromTestObject = OutPath & LongFileName
                End Function

This function will get the server path of the attachement based on the test object we have extracted in above function.

Public Function GetAttachmentServerPath (Object, FileName, LongFileName)
                Set AttachmentFactory = Object.Attachments
                Set AttachmentList = AttachmentFactory.NewList("")

                For Each Attachment in AttachmentList
                                If StrComp(Attachment.Name(1), FileName, 1) = False Then ' Equal
                                                LongFileName = Attachment.Name                                       
                                                Pos = Instr(1, Attachment.ServerFileName, Attachment.Name, 1)
                                                GetAttachmentServerPath = Left(Attachment.ServerFileName, Pos - 1)
                                                Exit Function
                                End If
                Next
                GetAttachmentServerPath = ""
End Function

Please let me know if you need any help on above functions.

Comments

Popular posts from this blog

UFT - Resolving scrolling issue if object is not visible

How to create a zip folder using VBScript

how to access the excel file as database in UFT?