haripotter’s technorati

Just another WordPress.com weblog

Download attachment from Quality center

 
HP Quality Center allows us to store any file as attachments. We could use this facility to store testdata, tools or anything that helps us to run a test successfully.

For example : We could store some command line tools in quality center as attachments in a folder. We could download these tools to the qtp system where we want to execute the tool. for such requirements, Try the below code to download an attachment from a testplan folder in qc.

‘Description : Returns the path of downloaded attachment
‘Example Usage :
‘ If you want to move the downloaded file to c:\ folder
‘ attpath = DownloadAttachment(“attachmentname”,”Root\D2D\Purchasing”, “TRUE”)

‘ If you DO NOT want to move the downloaded file to c:\ folder
‘ attpath = DownloadAttachment(“attachmentname”,”Root\D2D\Purchasing”, “FALSE”)

‘==================================================================================

Public Function DownloadAttachment(TDAttachmentName, TDFolderPath, bMovetoRoot)

Dim otaAttachmentFactory ‘As TDAPIOLELib.AttachmentFactory
Dim otaAttachment ‘As TDAPIOLELib.Attachment
Dim otaAttachmentList ‘As TDAPIOLELib.List
Dim otaAttachmentFilter ‘As TDAPIOLELib.TDFilter
Dim otaTreeManager ‘As TDAPIOLELib.TreeManager
Dim otaSysTreeNode ‘As TDAPIOLELib.SysTreeNode
Dim otaExtendedStorage ‘As TDAPIOLELib.TreeManager

Dim fso
Set fso = CreateObject(“Scripting.FileSystemObject”)

Dim strPath ‘As String

Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set otaAttachmentFilter = otaAttachmentFactory.Filter
otaAttachmentFilter.Filter(“CR_REFERENCE”) = “‘ALL_LISTS_” & otaSysTreeNode.NodeID & _
“_” & TDAttachmentName & “‘”
Set otaAttachmentList = otaAttachmentFilter.NewList
If otaAttachmentList.Count > 0 Then
set otaAttachment = otaAttachmentList.Item(1)
otaAttachment.Load True, “”
strPath = otaAttachment.FileName

if(bMovetoRoot) then
If (fso.FileExists(otaAttachment.FileName)) Then
fso.CopyFile strPath, “c:\”&TDAttachmentName
DownloadAttachment = “c:\”&TDAttachmentName
else
DownloadAttachment = strPath
end if
else
DownloadAttachment = strPath
end if
Else
Reporter.ReportEvent micFail, “Failure in library function ‘GetFolderAttachmentPath’”, _
“Failed to find attachment ‘” & TDAttachmentName & “‘ in folder ‘” & TDFolderPath & “‘.”
DowloadAttachment = “Empty”
End If

Set otaAttachmentFactory = Nothing
Set otaAttachment = Nothing
Set otaAttachmentList = Nothing
Set otaAttachmentFilter = Nothing
Set otaTreeManager = Nothing
Set otaSysTreeNode = Nothing
Set fso = nothing

End Function

April 29, 2008 - Posted by haripotter | HP Quality Center and QTP | , , , | 8 Comments

8 Comments »

  1. Hi How can we get the whole folder content present in my quality center server to my local system?

    Comment by Salman | July 18, 2008 | Reply

  2. [...] assuming he meant to download all the attachments from a specific folder in QC. I tweaked my earlier function  to download all the files instead of specific file. Here is the function.. [...]

    Pingback by Download all the attachments from a specific folder in QC « haripotter’s technorati | July 18, 2008 | Reply

  3. Hi ,

    some one let me know whether we can use QC as Shared folder… in the sense i want to upload Msaccess file manually .. and want to get and update value into it from local desktop….with out downloading file to local desktop.

    Comment by Prasan | July 29, 2008 | Reply

  4. Im sorry I’m new into this , mybe my question are of basic knowledge:

    attpath = DownloadAttachment(”attachmentname”,”Root\D2D\Purchasing”, “TRUE”)

    attpath is defined as?
    ”Root\D2D\Purchasing” this root corresponds to?

    Thankyou!

    Comment by Liliana | October 24, 2008 | Reply

  5. ”Root\D2D\Purchasing” this root corresponds to the Folder names in Quality center, where the attachment is present.

    Comment by haripotter | October 26, 2008 | Reply

  6. Thankyou Harry, that worked just fine. I am going to add a new thread. I have a doubt with the upload procedure now.
    Greetings!

    Comment by Liliana | November 6, 2008 | Reply

  7. Hi,

    I am trying to download test from qc to my local machine.
    when i open the test by using
    qtpApp.open [QC],folder path………
    qtp is responding like can’t open it as Application is busy.

    Can you help me on this

    Thanks
    jai

    Comment by Jai | May 9, 2009 | Reply

  8. Hi I need to download attachments from the currentTestSet in Test lab. Can u please advice? I don’t want the attachments in the folder of the test lab. I need attachments only from the current test set.

    Comment by nitin | June 25, 2009 | Reply


Leave a comment