1. File Name
2. Source Folder
3. Destination Folder
#################################################################################
Example:
File_Name = "Test Data.xls"
Folder_Name = "Subject\Automation-Regression\Test Data"
' Specify Destination folder path
Dest_Folder = "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\"
PassFailFlag = DownloadFileFromQC(Folder_Name,File_Name,Dest_Folder)
***********************************************************************************************************************************
***********************************************************************************************************************************
Public Function DownloadFileFromQC(Folder_Name,File_Name,Dest_Folder)
FilePath = GetAttachmentFromFolder(Folder_Name, File_Name, Dest_Folder)
If FilePath <> "" Then
' Step 2: Delete the file if it already exists
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Dest_Folder & File_Name) Then
objFSO.DeleteFile(Dest_Folder & File_Name)
End If
'Step 3: Rename the file
objFSO.MoveFile FilePath , Dest_Folder & File_Name
PassFailFlag = 0
ElseIf FilePath = "" Then
PassFailFlag = 1
End If
DownloadFileFromQC = PassFailFlag
End Function
' Get an attachment from Folder
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
'Get an attachment from Test Object
Public Function GetAttachmentFromTestObject (TestObject, FileName, OutPath)
MyPath = GetAttachmentServerPath(TestObject, FileName, LongFileName)
If StrComp(MyPath, "") = 0 Then
GetAttachment = ""
Reporter.ReportEvent Fail, "Specified file '"& File_Name &"' does not exsit in 'QC\ Test Plan\ Subject\ Automation-Regression\ Test Data' folder.",""
PassFailFlag = 1
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
Reporter.ReportEvent 0, "File '"& File_Name &"' downloaded into '"& Dest_Folder & "' folder.",""
PassFailFlag = 0
End Function
'Get an attachment Server Path
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
***********************************************************************************************************************************
***********************************************************************************************************************************
No comments:
Post a Comment