The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP Functional Testing / Mercury QuickTest Pro / QTP

Pages: 1
intothewarm
Newbie


Reged: 04/05/07
Posts: 5
How to get the exact attachment from QC in QTP?
      #373945 - 04/18/07 12:05 AM

Hi ALL:
I've got a problem when programming to download attachment from QC, the trouble is that my script downloads all attachments of a subject tree on QC, and I just need one of them, anyone who can help me? Below is my code:

---------------------------------------------------
Dim QCConnection
Dim attf
Set QCConnection = QCUtil.QCConnection
Set testtree = QCConnection.TreeManager
Set SubjectNode=testtree.TreeRoot("Subject")
Set node_Data=SubjectNode.FindChildNode("Data")
Set attf=node_Data.Attachments
Set attstorage=attf.AttachmentStorage
attstorage.ClientPath="C:\DATA\"
attstorage.Load
---------------------------------------------------------

In my code, I want to get the attachment(a xls file,named business.xls)of folder "Data", which is under a child node of "Subject" folder,but all attachments of the Subject tree is downloaded into C:\DATA\, can you help me?


Post Extras: Print Post   Remind Me!   Notify Moderator  
Tarun LalwaniModerator
Veteran


Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
Re: How to get the exact attachment from QC in QTP? [Re: intothewarm]
      #374110 - 04/18/07 10:19 AM

Go through the each item in the node_Data.Attachments collection and see which matches what you are looking for.

--------------------
Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **

KnowledgeInbox RSS


Post Extras: Print Post   Remind Me!   Notify Moderator  
maxj
Active Member


Reged: 01/14/04
Posts: 825
Loc: UK
Re: How to get the exact attachment from QC in QTP? [Re: Tarun Lalwani]
      #374241 - 04/19/07 02:59 AM

Try this:-

' Get an attachment from a test in Test Plan
Public Function GetAttachmentFromTest(FolderName, FileName, TestName, OutPath)
Dim testlist
Dim tst
Dim found

' reset flag
found = FALSE

Set TDConnection = QCUtil.TDConnection
Set treeManager = TDConnection.TreeManager
Set node = treeManager.nodebypath(FolderName)

' find the tests in the subject folder
Set subjNode = treeManager.nodebypath(FolderName)
Set testlist = subjNode.FindTests(TestName)


For Each tst in testlist
' find test object from test name
If tst.Name = TestName Then
found = TRUE
Exit For
End If
Next

If found = TRUE Then
'msgbox "tst.Name"
GetAttachmentFromTest = GetAttachmentFromTestObject (tst, FileName, OutPath)
Else
msgbox "test not found, please try again"
End If
End Function

--------------------
I like what i know and I know what i like


Post Extras: Print Post   Remind Me!   Notify Moderator  
sbksvm_1234
Newbie


Reged: 01/28/08
Posts: 1
Re: How to get the exact attachment from QC in QTP? [Re: maxj]
      #477179 - 04/21/08 12:47 PM

Hi,

I tried to use the function specified by you but I am getting a type mismatch error GetAttachmentFromTest = GetAttachmentFromTestObject (tst, FileName, OutPath). Do you have any clue for this error.

regards
Balakrishna S


Post Extras: Print Post   Remind Me!   Notify Moderator  
Reddy.k
Junior Member


Reged: 06/09/05
Posts: 84
Loc: SLC
Re: How to get the exact attachment from QC in QTP [Re: sbksvm_1234]
      #477472 - 04/22/08 08:46 AM

Hi,
You are getting that error because, the function given by Maxi is calling another function which is missing here.
Please do search with the text "Donate a user defined function to this topic ". You will find useful information on this.

Thanks


Post Extras: Print Post   Remind Me!   Notify Moderator  
TReddyModerator
Veteran


Reged: 01/17/07
Posts: 2565
Loc: Pittsburgh, PA
Re: How to get the exact attachment from QC in QTP [Re: sbksvm_1234]
      #477508 - 04/22/08 09:53 AM

Code:

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

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


' 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


FilePath = GetAttachmentFromFolder("Subject\TestOnly", "DB1.xls", "C:\Test\")
msgbox "Your file is located at folder: " & FilePath



Post Extras: Print Post   Remind Me!   Notify Moderator  
TReddyModerator
Veteran


Reged: 01/17/07
Posts: 2565
Loc: Pittsburgh, PA
Re: How to get the exact attachment from QC in QTP [Re: TReddy]
      #477513 - 04/22/08 10:09 AM

Easy methods to copy QC attachment to local filesystem:
........................................................
Method 1)
'Manually add QC attachment path in Folders tab
'Tools - > Options - > Folders - > [QualityCenter] Subject\........

Var = PathFinder.Locate("business.xls")
If Trim(Var) <> "" Then
CreateObject("Scripting.FileSystemObject").CopyFile Var, "C:\DATA\"
End If
........................................................
Method 2)
QCpath = "[QualityCenter] Subject\xxxxxxxxxx"
FileName = "business.xls"
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
'App.Folders.RemoveAll
App.Folders.Add(QCpath)
Var = PathFinder.Locate(FileName)
If Trim(Var) <> "" Then
CreateObject("Scripting.FileSystemObject").CopyFile Var, "C:\DATA\"
End If
'App.Folders.RemoveAll
Set App = Nothing


Post Extras: Print Post   Remind Me!   Notify Moderator  
Jpz
Newbie


Reged: 12/01/07
Posts: 23
Re: How to get the exact attachment from QC in QTP [Re: TReddy]
      #479940 - 04/30/08 04:10 PM

Quote:

Easy methods to copy QC attachment to local filesystem:
........................................................
Method 2)
QCpath = "[QualityCenter] Subject\xxxxxxxxxx"
FileName = "business.xls"
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
'App.Folders.RemoveAll
App.Folders.Add(QCpath)
Var = PathFinder.Locate(FileName)
If Trim(Var) <> "" Then
CreateObject("Scripting.FileSystemObject").CopyFile Var, "C:\DATA\"
End If
'App.Folders.RemoveAll
Set App = Nothing




Thank you!!!! This is very useful.


I noticed that QC path does not require the full path where the attachment would be. In my case the attachment I was looking for is in "Subject\Parent folder\Child folder\". I ran below code and it works!

<code start>
QCpath = "[QualityCenter] Subject\"
QCAttachmentFilename = "Input_Data.xls"

Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
'App.Folders.RemoveAll
App.Folders.Add(QCpath)
Var = PathFinder.Locate(QCAttachmentFilename)

If Trim(Var) <> "" Then
CreateObject("Scripting.FileSystemObject").CopyFile Var, "C:\"
Reporter.ReportEvent micPass, "FileCopied", "QC Attachment copied successfully to C:\"
Else
Reporter.ReportEvent micFail, "FileNotCopied", "QC Attachment Not Found or Not Copied"
End If

'App.Folders.RemoveAll
Set App = Nothing
<code end>


Regards,

Jpz


Post Extras: Print Post   Remind Me!   Notify Moderator  
puneet007
Newbie


Reged: 03/29/10
Posts: 12
Re: How to get the exact attachment from QC in QTP [Re: TReddy]
      #622307 - 04/14/10 12:17 PM

How can I delete an attachment from a test in the test lab by using a different test. For example: When I run the test1 it will attach a file and when I run the test2 it will retrieve the information from attachment in test1 and when done I want it to delete the attachment from test1. How can do this? below the code for the currenttest.

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

If QCUtil.CurrentSetTest.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


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 99 anonymous users are browsing this forum.

Moderator:  IanFraser, Rajkumar_Rajangam, thorwath, TReddy, AJ, Tarun Lalwani, mwsrosso 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 14999

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5