Highlighted
Super Contributor.. praveen_hpqc Super Contributor..
Super Contributor..
1703 views

Download all attachments from test lab using query.

Hello All,

@PhilTrostel,

I received request from team, they want all attachments phisically from test lab.

to my knowledge we can check attachments is added or not to test case or defect by using query but not sure how can we download bulk attachments physically.

Please help, thanks in advance.

Regards,

Praveen

Tags (1)
0 Likes
6 Replies
Micro Focus Expert
Micro Focus Expert

Re: Download all attachments from test lab using query.

I don't suggest using a query but, preferably, OTA objects to get the attachments. I coded this example in VB.Net which could be converted to vbscript easily enough. Note as I've placed comments on each relevant line to explain what I'm doing. Let me know if this helps...Cheers!

Module Module1

    Sub Main()
        ' OTA Client Command line Test Bed
        ' Designed by Phil Trostel
        ' Updated May 26, 2017
        Dim td As TDAPIOLELib.TDConnection
        Dim tFact As TDAPIOLELib.TestFactory
        Dim tList As TDAPIOLELib.List
        Dim tItem As TDAPIOLELib.Test
        Dim attFact As TDAPIOLELib.AttachmentFactory
        Dim attList As TDAPIOLELib.List
        Dim attItem As TDAPIOLELib.Attachment
        Try
            td = CreateObject("TDApiOle80.TDConnection.1")
            td.InitConnectionEx("http://localhost:8080/qcbin") 'enter QC url here
            td.Login("ptrostel", "") ' supply user name and pasword
            td.Connect("PHIL", "BlueFish") 'specify qc domain and project name
            If td.Connected = True Then 'check to see if the client is connected
                Console.WriteLine("Connected = " & td.Connected)
                tFact = td.TestFactory 'instantiate the TestFactory object
                tList = tFact.NewList("") 'instantate a List object and load it with all the Test Cases
                For Each tItem In tList 'iterate through the list of Test objects
                    If tItem.HasAttachment = True Then 'check if Attachment(s) exist
                        attFact = tItem.Attachments 'instantate the AttachmentFactory object
                        attList = attFact.NewList("") 'instantiate a List object and load it with Attachments in the singlar Test object
                        For Each attItem In attList 'iterate through the List of Attachments                         
                            attItem.Load(False, "") 'save the attachment to the client
                            Console.WriteLine(attItem.FileName) 'output showing where the file(s) are saved
                        Next
                    End If
                Next
            End If
            td.Disconnect() 'disconnect from the project
            td.Logout() 'logout of ALM
            td.ReleaseConnection() 'release the connection to ALM
            td = Nothing
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
        Console.WriteLine("Finished!!! - Hit any key to close")
        Console.ReadLine()
    End Sub

End Module

 

Phil Trostel
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Download all attachments from test lab using query.

You said "Test Case" which implies Test Plan so I coded that in the previous example. After I posted I see you're looking at the Test Lab which means "Test Instances". I coded that as well, here is the example...

Module Module1

    Sub Main()
        ' OTA Client Command line Test Bed
        ' Designed by Phil Trostel
        ' Updated May 26, 2017
        Dim td As TDAPIOLELib.TDConnection
        Dim tsTestFact As TDAPIOLELib.TSTestFactory
        Dim tsTestList As TDAPIOLELib.List
        Dim tsItem As TDAPIOLELib.TSTest
        Dim attFact As TDAPIOLELib.AttachmentFactory
        Dim attList As TDAPIOLELib.List
        Dim attItem As TDAPIOLELib.Attachment
        Try
            td = CreateObject("TDApiOle80.TDConnection.1")
            td.InitConnectionEx("http://localhost:8080/qcbin") 'enter QC url here
            td.Login("ptrostel", "") ' supply user name and pasword
            td.Connect("PHIL", "BlueFish") 'specify qc domain and project name
            If td.Connected = True Then 'check to see if the client is connected
                Console.WriteLine("Connected = " & td.Connected)
                tsTestFact = td.TSTestFactory 'instantiate the TSTestFactory object
                tsTestList = tsTestFact.NewList("") 'instantate a List object and load it with all the Test Instances
                For Each tsItem In tsTestList 'iterate through the list of TSTest objects
                    If tsItem.HasAttachment = True Then 'check if Attachment(s) exist
                        attFact = tsItem.Attachments 'instantate the AttachmentFactory object
                        attList = attFact.NewList("") 'instantiate a List object and load it with Attachments in the singlar Test Instance
                        For Each attItem In attList 'iterate through the List of Attachments                         
                            attItem.Load(False, "") 'save the attachment to the client
                            Console.WriteLine(attItem.FileName) 'output showing where the file(s) are saved
                        Next
                    End If
                Next
            End If
            td.Disconnect() 'disconnect from the project
            td.Logout() 'logout of ALM
            td.ReleaseConnection() 'release the connection to ALM
            td = Nothing
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
        Console.WriteLine("Finished!!! - Hit any key to close")
        Console.ReadLine()
    End Sub

End Module
Phil Trostel
0 Likes
Super Contributor.. praveen_hpqc Super Contributor..
Super Contributor..

Re: Download all attachments from test lab using query.

Thank you for your help Phil Trostel..!

I will try in my environment.

Regards,

Praveen

0 Likes
Abhilash
Visitor.

Re: Download all attachments from test lab using query.

Hi Phil ,

i try this code but getting error that object not support this property at creating new list.

0 Likes
New Member.. gaurav shankar
New Member..

Re: Download all attachments from test lab using query.

Hi

Can u tell me that where i need to execue this code to export the  attachments of test instances.

Thanks,

Gaurav

0 Likes
NEW_ALM12 Outstanding Contributor.
Outstanding Contributor.

Re: Download all attachments from test lab using query.

@PhilTrostel , Hi Phil, 

Im poked alot into your code to meet my requirement. But, still I did not make much progress. 

Would you be able to modify your TestLab code to meet my below two requirements please?

1) How do I save attachent into my desire location. Do not want to save in default location. 

2) How do I download attachments from test instances that are in particular Test set. In addition, I may have multiple TestSets with in test set folder.

Thank you in advance!

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.