You are on page 1of 9

'Example 1. To Download file from a Folder Attachment in QC '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FilePath = GetAttachmentFromFolder("Subject\StayConnected\Release 1.0\Stay_Automation\Modules\MP_Module\Data_Tables", "abc.

vbs", "C:\QC_Files\") msgbox "Your file is located at folder: " & FilePath

'Examples 2: To Download file from the current Test Attachment '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FilePath = GetAttachment("abc.vbs", "C:\QC_Files\") MsgBox "Your file is here:" & FilePath

'Examples 3: To Download file from a different Test Attachment '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FilePath = GetAttachmentFromTest("Driver_Script", "abc.vbs", "C:\QC_Files\") MsgBox "Your file is here:" & FilePath

'Examples 4: To Save File to Folder Attachment in QC '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttachFileToTDFolder "Data_Tables","C:\QC\abc.vbs", "Test Description" Msgbox "The File has been successfully saved to the specified Folder"

'Examples 5: To Save File to Current Test Attachment in QC '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SaveAttachment "C:\QC\abc.vbs", "Test Description" Msgbox "The File has been successfully saved to the Current Test"

'Examples 6: To Save File to Different Test Attachment in QC '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SaveAttachmentToTest "Driver_Script", "C:\QC\abc.vbs", "Test Description in Japanese" Msgbox "The File has been successfully saved to the specified Test"

'Examples 7: To get the local path of the file which is attached to the current test in the Quality centre '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ Environment.Value("RelativePath") =GetTestAttachmentPath("Driver_Script.xls") RelativePath = Environment.Value("RelativePath")

DataTable.ImportSheetRelativePath,"Driver_Script", "Driver_Script"

'Examples 8: To get the local path of the file which is attached to a folder in QC '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ Environment.Value("RelativePath") = GetFolderAttachmentPath("Driver_Script.xls","Subject\StayConnected\Release 1.0\Stay_Automation\Driver\Data_Tables") RelativePath = Environment.Value("RelativePath") DataTable.ImportSheet RelativePath,"Driver_Script", "Driver_Script"

'************************************************************************* ********************************************** ' Function Name : AttachFileToTDFolder ' Function Details : Saves an Attachment to the Specified Folder ' Function Input Value : TDFolderName,LocalFile, FileDescrip ' Input details : ' TDFolderName - The correponding Folder name in QC where the file has to be attached. ' LocalFile - The Name of the file which has to be attached to the Quality Centre ' FileDescrip - Description of the file (Description field on Quality Centre) '************************************************************************* ********************************************** Function AttachFileToTDFolder(TDFolderName,LocalFile, FileDescrip) On Error Resume Next Set Qc = QCUtil.TDconnection Set tm = Qc.TreeManager Set root = tm.TreeRoot("Subject") Set childNode = root.FindChildNode("StayConnected") Set childNode1 = childNode.FindChildNode("Release 1.0") Set childNode2 = childNode1.FindChildNode("Stay_Automation") Set childNode3 = childNode2.FindChildNode("Modules") Set childNode4 = childNode3.FindChildNode("MP_Module") Set childNode5 = childNode4.FindChildNode(TDFolderName) Set foldAttachments = childNode5.Attachments Set foldAttachment = foldAttachments.AddItem(Null) foldAttachment.FileName =LocalFile foldAttachment.Description = FileDescrip foldAttachment.Type = 1

foldAttachment.Post End Function

'************************************************************************* ********************************************** ' Function Name : GetAttachmentFromFolder ' Function Details : To download an attachment from the specified folder in Quality Centre ' Function Input Value : FolderName, FileName, OutPath ' Input details : ' FolderName - The correponding Folder name in QC where the file is attached. ' FileName - The Name of the file which has to be downloaded to the local system ' OutPath - The local path in the system where the file has to be downloaded. '************************************************************************* ********************************************** 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 '************************************************************************* ********************************************** ' Function Name : GetAttachment ' Function Details : To download an attachment from the current test. ' Function Input Value : FileName, OutPath ' Input details : ' FileName - The Name of the file which has to be downloaded to the local system ' OutPath - The local path in the system where the file has to be downloaded. '************************************************************************* ********************************************** Public Function GetAttachment(FileName, OutPath) Set CurrentTest = TDUtil.CurrentTest GetAttachment = GetAttachmentFromTestObject(CurrentTest, FileName, OutPath) End Function '************************************************************************* ********************************************** ' Function Name : GetAttachmentFromTest ' Function Details : To download an attachment from another test in the Quality Centre ' Function Input Value : TestName, FileName, OutPath

' ' ' '

Input details : TestName - The Name of the test in Quality Centre where the file is attached. FileName - The Name of the file which has to be downloaded to the local system OutPath - The local path in the system where the file has to be downloaded.

'************************************************************************* ********************************************** Public Function GetAttachmentFromTest(TestName, FileName, OutPath) Set TDConnection = TDUtil.TDConnection Set TestList = TDConnection.TestFactory.NewList("SELECT * FROM TEST WHERE TS_NAME = '" & TestName & "'") GetAttachmentFromTest = GetAttachmentFromTestObject(TestList(1), FileName, OutPath) End Function

'************************************************************************* ********************************************** ' Function Name : GetAttachmentServerPath ' Function Details : To Get the Server path in the Quality Centre ' Function Input Value : TestObject, FileName, LongFileName ' Input details : ' TestObject - The QC object ' FileName - The Name of the file which has to be downloaded to the local system ' LongFileName - The Long file Name that QC generates for an attached file. '************************************************************************* ********************************************** Public Function GetAttachmentServerPath (TestObject, FileName, LongFileName) Set AttachmentFactory = TestObject.Attachments Set AttachmentList = AttachmentFactory.NewList("SELECT * FROM CROS_REF") For Each Attachment in AttachmentList If StrComp(Attachment.Name(1), FileName, 1) = False Then 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 '*************************************************************************

********************************************** ' Function Name : GetAttachmentFromTestObject ' Function Details : To Get the attachment from the test object ' Function Input Value : TestObject, FileName, OutPath ' Input details : ' TestObject - The QC object ' FileName - The Name of the file which has to be downloaded to the local system ' OutPath - The local path in the system where the file has to be downloaded. '************************************************************************* ********************************************** 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 ExtendedStorage.SaveAs OutPath End Function

'************************************************************************* ********************************************** ' Function Name : SaveAttachment ' Function Details : To Upload an attachment to the current test in Quality Centre ' Function Input Value : LocalFilePath, FileDescription ' Input details : ' LocalFilePath - Path indicating the location of the attachment on the local filesystem ' FileDescrip - Description of the file (Description field on Quality Centre) '************************************************************************* **********************************************

Public Function SaveAttachment(LocalFilePath, FileDescription) SaveAttachmentToTestObj QCUtil.CurrentTest, LocalFilePath, FileDescription End Function

'************************************************************************* ********************************************** ' Function Name : SaveAttachmentToTest ' Function Details : To Upload an attachment to the indicated Test in Quality Centre ' Function Input Value : TestName, LocalFilePath, FileDescription ' Input details ' TestName - The Name of the test in Quality Centre where the file has to be attached. ' LocalFilePath - Path indicating the location of the attachment on the local filesystem ' FileDescrip - Description of the file (Description field on Quality Centre) '************************************************************************* ********************************************** Public Function SaveAttachmentToTest(TestName, LocalFilePath, FileDescription) Set TestList = TDUtil.TDConnection.TestFactory.NewList("SELECT * FROM TEST WHERE TS_NAME = '" & TestName & "'") If TestList.Count = 0 Then Exit Function End If SaveAttachmentToTestObj TestList(1), LocalFilePath, FileDescription End Function

'************************************************************************* ********************************************** ' Function Name : SaveAttachmentToTestObj ' Function Details : To save the attachment to the test object ' Function Input Value : TestObj, LocalFilePath, FileDescription ' Input details ' TestObj - QC Test Object ' LocalFilePath - Path indicating the location of the attachment on the local filesystem ' FileDescrip - Description of the file (Description field on Quality Centre) '************************************************************************* ********************************************** Public Sub SaveAttachmentToTestObj(TestObj, LocalFilePath, FileDescription)

Set Attachments = TestObj.Attachments Set Attachment = Attachments.AddItem(Null) Attachment.FileName = LocalFilePath Attachment.Description = FileDescription Attachment.Type = 1'TDATT_FILE Attachment.Post ' Commit changes End Sub

'************************************************************************* ********************************************** ' Function Name : GetTestAttachmentPath ' Function Details : To Get the path of the attachments which are attached to the current test in the Quality Centre ' Function Input Value : TDAttachmentName ' Input details ' TDAttachmentName - The Name of the attachment which is attached to the current test. '************************************************************************* ********************************************** Public Function GetTestAttachmentPath(TDAttachmentName) Dim objAttachmentFactory Dim objAttachment Dim objAttachmentList Dim objAttachmentFilter Dim objExtendedStorage Dim strPath 'As String Set objAttachmentFactory = QCUtil.CurrentTest.Attachments Set objAttachmentFilter = objAttachmentFactory.Filter objAttachmentFilter.Filter("CR_REFERENCE") = "'TEST_" & QCUtil.CurrentTest.Id & "_" & TDAttachmentName & "'" Set objAttachmentList = objAttachmentFilter.NewList If objAttachmentList.Count = 1 Then Set objAttachment = objAttachmentList.Item(1) objAttachment.Load True, "" strPath = objAttachment.FileName ElseIf objAttachmentList.Count > 1 Then Reporter.ReportEvent micFail, "Failure in library function 'GetTestAttachmentPath'", "Found more than one attachment '" & TDAttachmentName & "' in test '" &QCUtil.CurrentTest.Name & "'." strPath = "" ElseIf objAttachmentList.Count < 1 Then Reporter.ReportEvent micFail, "Failure in library function 'GetTestAttachmentPath'","Found 0

attachments '" & TDAttachmentName & "' in test '" & QCUtil.CurrentTest.Name & "'." strPath = "" End If GetTestAttachmentPath = strPath Set objAttachmentFactory = Nothing Set objAttachment = Nothing Set objAttachmentList = Nothing Set objAttachmentFilter = Nothing End Function

'************************************************************************* ********************************************** ' Function Name : GetFolderAttachmentPath ' Function Details : To Get the path of the attachments which is attached to a folder in Quality Centre ' Function Input Value : TDAttachmentName, TDFolderPath ' Input details ' TDAttachmentName - The Name of the attachment which is attached to the folder in QC ' TDFolderPath - The path of the folder in QC where the attachment is present '************************************************************************* ********************************************** Public Function GetFolderAttachmentPath(TDAttachmentName, TDFolderPath) Dim objAttachmentFactory Dim objAttachment Dim objAttachmentList Dim objAttachmentFilter Dim objTreeManager Dim objSysTreeNode Dim objExtendedStorage Dim intNdId Dim strPath Set objTreeManager = QCUtil.TDConnection.TreeManager Set objSysTreeNode = objTreeManager.NodeByPath(TDFolderPath) Set objAttachmentFactory = objSysTreeNode.Attachments Set objAttachmentFilter = objAttachmentFactory.Filter intNdId = objSysTreeNode.NodeID objAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & intNdId & "_" & TDAttachmentName & "'" Set objAttachmentList = objAttachmentFilter.NewList If objAttachmentList.Count > 0 Then Set objAttachment = objAttachmentList.Item(1)

objAttachment.Load True, "" strPath = objAttachment.FileName Else Reporter.ReportEvent micFail,"Failure in library function 'GetFolderAttachmentPath'", "Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'." End If GetFolderAttachmentPath = strPath Set objAttachmentFactory = Nothing Set objAttachment = Nothing Set objAttachmentList = Nothing Set objAttachmentFilter = Nothing Set objTreeManager = Nothing Set objSysTreeNode = Nothing End Function