Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive (1998 Views)
Reply
Occasional Visitor
Prasanth kumar_1
Posts: 3
Registered: ‎02-03-2009
Message 1 of 17 (1,998 Views)

(QualityCenter)How can i extract attachments in TestPlan to a local drive

I Created a Test Plan of Type VAPI-XP-TEST which uses VB Script with 1 attachment say(attach1).
In Test Script:
I want to extract this attachment at run time,copy it to a Local drive and triggers command which uses this attachment.
Can u Please help me out with code which extracts attachment and copy it to a local drive??
I searched on Forum but didn't get a solution.
Please use plain text.
Honored Contributor
Rhonda Robinson
Posts: 3,159
Registered: ‎11-13-2007
Message 2 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

You may be able to use the FSO functions/methods. Using these, we are able to copy files from one directory to another.
Please use plain text.
Honored Contributor
Jan Czajkowski
Posts: 2,079
Registered: ‎12-12-2007
Message 3 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Here is some sample OTA API code that I have used in the past:

'Get the client temp folder - create it if it does not exist
Set flib = CreateObject("Scripting.FileSystemObject")
If Not flib.FolderExists(flib.GetSpecialFolder(2)) Then
flib.CreateFolder(flib.GetSpecialFolder(2))
End If
tempfolder = flib.GetSpecialFolder(2)

'Get the folder where the data file is attached
Set tdc = TDConnection
set tm = tdc.TreeManager
set root = tm.TreeRoot("Subject")
set folder = root.FindChildNode("QTP")
Set fact = folder.Attachments
Set alist = fact.NewList("")

'Find the right attachment and download it to the temp folder
For Each att In alist
Set ext = att.AttachmentStorage
attname = att.DirectLink
If InStr(attname, "MyDataFile.xls") > 0 Then
ext.Load attname, True
'Copy the attachment to a file with the original filename
flib.CopyFile ext.ClientPath & "\" & attname, tempfolder & "\" & "MyDataFile.xls"
Exit For
End If
Next
Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
Please use plain text.
Occasional Visitor
Prasanth kumar_1
Posts: 3
Registered: ‎02-03-2009
Message 4 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Thanks for your reply Jan Czajkowski,
But this code is to copy from QC Folder attachments to Local Drive but i need to copy the attachment present in Test. I tried for reference of Test object but Unsuccessful.

Could u Help me more....
Please use plain text.
Honored Contributor
Jan Czajkowski
Posts: 2,079
Registered: ‎12-12-2007
Message 5 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

If you already have a reference to the Test, the code to get the Attachment should be identical. Are you having problems finding the Test? Are you trying to find it by ID or by name?
Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
Please use plain text.
Occasional Visitor
Prasanth kumar_1
Posts: 3
Registered: ‎02-03-2009
Message 6 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

I didn't get Test Object reference....I tried in similar fashion as above.
From folder object, I tried to get test object but unsuccessful...simply(Access to folder child needed).

My Problem is
how can we get Test Object reference through Tree Manager. Here we got up to folder.

I can use the above code as alternative if i can't get test attachments but to be more precise i need to get test attachments
Please use plain text.
Honored Contributor
Jan Czajkowski
Posts: 2,079
Registered: ‎12-12-2007
Message 7 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

You use the TestFactory object to get hold of a Test object. You can use the global TestFactory and filter on the ID or name, or you can use a TestFactory that is specific to a folder if you have a reference to the folder. It all depends on how you identify the Test. How do you want to do that?
Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
Please use plain text.
Trusted Contributor
Percy Bell
Posts: 348
Registered: ‎09-18-2008
Message 8 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Here is my functions to get the job done:

''
'Retrieves an attachment from any test case
'@Param TestName The name of the test case that contains the attachment
'@Param FileName The file name of the attachment
'@Param OutPath The path to which to save the file
'@return Path including filename of the attachment on the local filesystem.

'@Description Retrieve an attachment from any test case
'@Documentation Retrieve from and save it to
Public Function GetAttachmentFromTest(ByVal TestName, ByVal FileName, ByVal OutPath)
Dim TDConnection
Set TDConnection = QCUtil.TDConnection

Dim TestList
Set TestList = TDConnection.TestFactory.NewList("SELECT * FROM TEST WHERE TS_NAME = '" & TestName & "'")

GetAttachmentFromTest = GetAttachmentFromTestObject(TestList(1), FileName, OutPath)
End Function

''
'Retrieves an attachment from a test object to a local file.
'@Param Object The test object that contains the attachment
'@Param FileName The File Name of the attachment
'@Param OutPath The path to which to save the file
'@return Path including filename of the attachment on the local filesystem.

'@Description Retrieves an attachment from a test object to a local file.
'@Documentation Retrieves from a test object to
Public Function GetAttachmentFromTestObject(ByRef Object, ByVal FileName, ByVal OutPath)
Dim strRetVal
strRetVal = ""

Dim AttachmentFactory, AttachmentList
Set AttachmentFactory = Object.Attachments
Set AttachmentList = AttachmentFactory.NewList("")

'Ensure path ends with "\"
If Right(OutPath, 1) <> "\" Then
OutPath = OutPath & "\"
End If

Dim Attachment, LongFileName, ExtendedStorage
For Each Attachment In AttachmentList
If StrComp(Attachment.Name(1), FileName, 1) = False Then ' Equal
LongFileName = Attachment.Name 'Actual ServerFileName of attachment in QC.
Set ExtendedStorage = Attachment.AttachmentStorage
ExtendedStorage.ClientPath = OutPath
ExtendedStorage.Load LongFileName, True


Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Rename(move) file to what we expect the file to be named and not the ServerFileName.
objFSO.MoveFile OutPath & LongFileName, OutPath & FileName
strRetVal = OutPath & FileName

Set objFSO = Nothing
Exit For
End If
Next

GetAttachmentFromTestObject = strRetVal
End Function
Please use plain text.
Occasional Visitor
Nileshdr1
Posts: 3
Registered: ‎07-15-2009
Message 9 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Hi,

Can you please give me the code to upload the attachment to Test Cases
Please use plain text.
Occasional Visitor
soumyavinay
Posts: 5
Registered: ‎01-29-2010
Message 10 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Hi Here is a code to Upload attachments to the Current testcase

FilePath = "C:\abc.xml"
Set ObjCurrentTest = QCUtil.CurrentTest.Attachments
Set ObjAttch = ObjCurrentTest.AddItem(Null)
ObjAttch.FileName = FilePath
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh


Please use plain text.
Honored Contributor
Eric Schumacher
Posts: 920
Registered: ‎11-13-2007
Message 11 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

You guys are all making this much harder than you need.

You can simply use the built in TDHelper object in VAPI.

DownLoadAttachment()

See the QC User guide for other helpful build in objects and methods. Section: Working with Vapi-xp.

Eric Schumacher
TDForums.com
www.TDForums.com
Please use plain text.
Occasional Visitor
soumyavinay
Posts: 5
Registered: ‎01-29-2010
Message 12 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Hi Eric,

How can i download resources from test Resource Module of QC and Upload a resource too thru QTP
Please use plain text.
Honored Contributor
Eric Schumacher
Posts: 920
Registered: ‎11-13-2007
Message 13 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Please don't hijack threads esp if you have already created another thread on the same topic.

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1404055
www.TDForums.com
Please use plain text.
Occasional Visitor
pvarma
Posts: 5
Registered: ‎03-28-2010
Message 14 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

I get an type mismatch on GetAttachmentFromTestObject based on the code below from another user.

Public Function GetAttachmentFromTest(ByVal TestName, ByVal FileName, ByVal OutPath)
Dim TDConnection,GetAttachmentFromTestObject
Set TDConnection = QCUtil.TDConnection

Dim TestList
Set TestList = TDConnection.TestFactory.NewList("SELECT * FROM TEST WHERE TS_NAME = '" & TestName & "'")

GetAttachmentFromTest = GetAttachmentFromTestObject(TestList(1), FileName, OutPath)
End Function

Please use plain text.
Honored Contributor
Jan Czajkowski
Posts: 2,079
Registered: ‎12-12-2007
Message 15 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

You always need to use Set when you return an object:

Set GetAttachmentFromTest = GetAttachmentFromTestObject(TestList(1), FileName, OutPath)
Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
Please use plain text.
Occasional Visitor
pvarma
Posts: 5
Registered: ‎03-28-2010
Message 16 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

I have retrieve an attachement from a different test script and now I want to delete the attachment from the different test script. The current test does not have an attachment.

Function RemoveQCAttachements(NameOfTheFile)
var_count= QCUtil.CurrentTestSet.Attachments.NewList("").count
For i= 1 to var_count

If QCUtil.CurrentTestSet.Attachments.NewList("").Item(1).Name =NameOfTheFile Then
AttachmentID = QCUtil.CurrentTestSet.Attachments.NewList("").Item(1).ID
QCUtil.CurrentTestSet.Attachments.RemoveItem(AttachmentID)
End If

Next
End Function
Please use plain text.
Occasional Visitor
maheshja
Posts: 3
Registered: ‎07-28-2010
Message 17 of 17 (1,998 Views)

Re: (QualityCenter)How can i extract attachments in TestPlan to a local drive

Hi i need help on how to create folder in QC by using VB script

EX:subject\projexcs

please need a code
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation