Hello Friends,
In this post, we will discuss downloading the attachments from Test plan module of ALM/QC. Downloading attachments from test plan is little trickier then downloading attachments from requirements module or defects module because we have two distinct places from where we can download attachments, first one is a test case and second is individual design steps.
You can read about downloading attachments from requirements module here and about downloading the attachments from defects here.
Introduction
For downloading test and design step attachments, first, we have to establish the connection to ALM/QC using OTA API, which is explained here.
In this post we will discuss three different approaches, first is downloading all test attachments, second is downloading attachments from a single test and from all its design steps.
Downloading all tests attachments
After you have successfully created the Object of TDConnection, then Copy the following function into your code execute the scripts, all of the test attachments will be downloaded in the desired folder.
public static Boolean DownloadTestAttachments_New(String AttachmentDownloadPath) { TDAPIOLELib.TestFactory OTestFactory = OQConnection.TestFactory as TDAPIOLELib.TestFactory; TDAPIOLELib.TDFilter OTDFilter = OTestFactory.Filter as TDAPIOLELib.TDFilter; TDAPIOLELib.List OTestList; TDAPIOLELib.AttachmentFactory OAttachmentFactory; TDAPIOLELib.ExtendedStorage OExtendedStorage; Console.WriteLine("Downloading attachments for the Tests : " + AttachmentDownloadPath); try { //Check if the directory exists if ((System.IO.Directory.Exists(AttachmentDownloadPath)) == false) { Debug.WriteLine("Cannot find the attachments download folder"); return false; } OTDFilter["TS_ATTACHMENT"] = "Y"; OTestList = OTestFactory.NewList(OTDFilter.Text); foreach (TDAPIOLELib.Test OTest in OTestList) { if (OTest.HasAttachment) { Directory.CreateDirectory(AttachmentDownloadPath + "\\" + OTest.ID.ToString()); Console.WriteLine("Downloading attachments for the Test : " + OTest.Name.ToString()); OAttachmentFactory = OTest.Attachments; //Download the test attachments foreach (TDAPIOLELib.Attachment OAttachment in OAttachmentFactory.NewList("";)) { OExtendedStorage = OAttachment.AttachmentStorage; OExtendedStorage.ClientPath = AttachmentDownloadPath + "\\" + OTest.ID.ToString(); OAttachment.Load(true, OAttachment.Name); } } } return true; } catch (Exception ex) { Debug.WriteLine("Error occurred while downloading the attachments : " + ex.Message.ToString()); return false; } }
How downloading test attachment works
For downloading the attachments from tests, we will use the following objects
- TestFactory : Test Factory object is the test manager class of OTA API. This can be used for creating and managing the tests.
- Test : Test is the actual test object, which will represent a single test at any given point of time.
- TDFilter : TDFiler Object if the Filter type object of the OTA API and can be used for filtering data from any modules.
- AttachmentFactory : Attachment Factory Object is the Attachment manager class of OTA API. This will be used for managing the attachments.
- ExtendedStorage : it is the storage handler object of the OTA API and will be used for downloading the attachment to the desired folder.
For downloading the test attachments, first we have to filter the test with attachments; otherwise, it might take a lot of time for the bigger projects to navigate through all of the tests.
ALM will store value ‘Y’ in the field “TS_ATTACHMENT” and we will use this field to filter the test with attachments.
OTDFilter["TS_ATTACHMENT"] = "Y"; OTestList = OTestFactory.NewList(OTDFilter.Text);
After the execution of the above statements, we will get the list of test objects with attachments in OTestList object.
Now, for each of the listed tests, we will get the attachments object
OAttachmentFactory = OTest.Attachments;
And then we will download the attachments using the extended storage objects.
Downloading attachments from design steps
Downloading attachments from tests is an easy task because we can apply filters on tests, but downloading attachments from design steps is a bit tricky part, to download design steps attachments, we will need design step factory objects which can only be obtained using test object. So, to read the design steps we will have to get the test object and then only we can get information about the design steps.
If you have a bigger project and a lot of random design steps are having the attachments then you will have to figure out a way to filter on the tests from which you want to download the design steps. There is an another easier way of finding the design steps using the query on the DESSTEPS table
Select distinct(DS_TEST_ID) from DESSTEPS where DS_ATTACHMENT = ‘Y’
Note : You will need QC database access to execute this query or you will have to use OTA Command object for executing this query
Once you execute this query you will get the list of tests whose design steps are having attachments.
you can use the below code for downloading the attachments.
public static Boolean DownloadDesignStepsAttachmentsWithTestID_New(String TESTID, String AttachmentDownloadPath) { TDAPIOLELib.TestFactory OTestFactory = OQConnection.TestFactory as TDAPIOLELib.TestFactory; TDAPIOLELib.TDFilter OTDFilter = OTestFactory.Filter as TDAPIOLELib.TDFilter; TDAPIOLELib.List OTestList; TDAPIOLELib.AttachmentFactory OAttachmentFactory; TDAPIOLELib.ExtendedStorage OExtendedStorage; TDAPIOLELib.DesignStepFactory ODesignStepFactory; TDAPIOLELib.Test OTest; Console.WriteLine("Downloading attachments for the Tests : " + AttachmentDownloadPath); try { //Check if the directory exists if ((System.IO.Directory.Exists(AttachmentDownloadPath)) == false) { Debug.WriteLine("Cannot find the attachments download folder"); return false; } OTDFilter["TS_TEST_ID"] = TESTID; OTestList = OTestFactory.NewList(OTDFilter.Text); if (OTestList != null && OTestList.Count == 1) { OTest = OTestList[1]; ODesignStepFactory = OTest.DesignStepFactory; foreach (TDAPIOLELib.DesignStep ODesignStep in ODesignStepFactory.NewList("")) { if (ODesignStep.HasAttachment) { OAttachmentFactory = ODesignStep.Attachments; //Download the Design Step Attachments foreach (TDAPIOLELib.Attachment OAttachment in OAttachmentFactory.NewList("")) { OExtendedStorage = OAttachment.AttachmentStorage; OExtendedStorage.ClientPath = AttachmentDownloadPath; OAttachment.Load(true, AttachmentDownloadPath + "\\" + OAttachment.Name); } } } } return true; } catch (Exception ex) { Debug.WriteLine("Error occurred while downloading the attachments : " + ex.Message.ToString()); return false; } }
How it works?
For downloading the Design step attachments we will need the reference to the Designstep factory from the test object. So, we will use the passed test ID to filter and get the test object. Once we have the test object reference, then we will get the design step factory reference from it.
Using this design step factory reference we will loop through all of the design steps for finding if the design step is having an attachment.
if (ODesignStep.HasAttachment)
Lastly, we will use the extended storage object for downloading the attachments from the design steps object.
Let me know, if you need any help, I will try to provide the solutions.
Thanks,
Hello Mr. Sumeet Singh Kushwah, I have read your four posts about using OTA API, and the objects under QCUtil.QCConnection (OQConnection.BugFactory, OQConnection.ReqFactory, OQConnection.TestFactory). I am looking for a way to access the VBScript code for Business Components, and am trying variations of QCConnection.TreeManager.TreeRoot(“Subject”). I know that the BC VBScript is stored as plain text on the server, and have found how to analyze it (see, for example, http://quicklearnautomation.blogspot.ch/ Get All Function Names and Count From Library File), but do not have access to the text file on the ALM server. Can you suggest a way to get this source code through the OTA API? Thank you in advance, Tim.
LikeLike
Are you looking for below script ?
Set qtApp = CreateObject(“QuickTest.Application”)
qtApp.Launch
qtApp.Visible = True
qtApp.OpenBusinessComponent “[QualityCenter] Components\Folder\ComponentName”, False, False
Set myComp = qtApp.BusinessComponent
Set myAct = myComp.Actions.Item(1)
strScript = myAct.GetScript
”’ Analyse Scripts here
LikeLike
Hello Mr. Sumeet Singh Kushwah, Thank you for this reply. I apologize for crossing messages. I’ll have a look at your suggestion (Set qtApp = CreateObject(“QuickTest.Application”) …). Thank you for your response. Best, Tim
LikeLike
Update to my last post: I could download the OTA API Reference (HTML, Version 11.50). I can find the “BPComponent” in the Class Diagram for “Business Process”. So, how can I get this object – an instance of BPIteration or by starting at the “Component Folder Factory”? And, if I get to a BPComponent, will I get the VBScript source code? Thanks in advance, Tim
LikeLike
Hi Tim,
use the below code for getting the BPIterations Object
Dim objTestFactory As TestFactory
Dim objTest As Test
Dim BPTest As BusinessProcess
Dim components As List
Dim Component As BPComponent
Dim params As List, tList As List
Dim iterations As List
Dim iteration As BPIteration
Set objTestFactory = tdc.TestFactory
Set tList = objTestFactory.NewList(“”)
‘ Get any Business Process test.
Dim tst As Test
For Each tst In tList
Debug.Print tst.Type
If tst.Type = “BUSINESS-PROCESS” Then
Set objTest = tst
Exit For
End If
Next tst
If objTest Is Nothing Then Exit Sub
Set BPTest = objTest
BPTest.Load
Set components = BPTest.BPComponents
Set Component = components.Item(1)
Set iterations = Component.iterations
Set iteration = iterations.Item(1)
Thanks,
Sumeet Singh Kushwah
LikeLike
Hi Sumeet,
I’m currently using HP performance center ALM for performance testing, I want to know how and where to start to write an automated code to download multiple scripts from a folder in HPPC. Is there a way we can create a n excel utility for the same?
LikeLike
Is is possible to mass download test case attachments from Test Lab
LikeLike
Hi Thirupathi,
Yes its possible to download the attachments from test lab. You just need to the object of test from the lab and use the same attachment factory and extended storage objects to download the attachments
Thanks,
Sumeet Singh kushwah
LikeLike
Can you provide the code for downloading attachments from test lab for all the test runs from a specific test set?
LikeLike
how can i execute the code in this article.?
this code written in which language?
LikeLike
The code is written in c#. You can execute it using any c# code or easily change it to vba code if u want to execute it in excel macros. You will need to create the TDConnection Object.
Let me know, if u need anything else.
Thanks,
Sumeet
LikeLike
Thanks for the quick response.
One more question–>
one of the function parameter ( AttachmentDownloadPath ) is file repository location
where in my case its onpremisis server location –>
C:\ProgramData\HP\ALM\repository\qc\abc\xyz\ProjRep\000\000\000\001
can i pass directly the above server repository location to the function???
LikeLike
Yes you can pass that
LikeLike
Thanks sumeet.
I converted c# code to vb and want to execute in excel macro.
How to include this function in below existing macro code???
in macro have already working code for ALM connection
(which i taken from one of your post –> https://sumeetkushwah.com/2015/03/19/connecting-almqc-using-hps-otaopen-test-architecture-api/).
can you help me how to execute this download attachments function.
LikeLike
i tried to convert the code using –> http://converter.telerik.com/
but code not fully conevrted to VBA.
If possible can you provide me the fully converted VBA code for the c# code???
LikeLike
is there a script to download attachments from Test Step, Test Case in Test Lab
LikeLike
hi can u help me to run any query from ALM using VBA
LikeLike
What help do you need ? Have you tried anything yet ?
LikeLike
Hi can you help in VB Script,that am able to get the list of attachments means count of attachemnts in the that test case,but confused that i gave the path but not downloaded to my local.Also am not sure how to see the attachment name after getting list .
Attachmentstorage.ClientPath = “C\test\”&”Test.xls”
Attachmentstorage.Load
LikeLiked by 1 person
Attachmentstorage.ClientPath should be “C\test”
and you need the attachment object for downloading the attachments like below
Attachmentstorage = OAttachment.AttachmentStorage;
Attachmentstorage.ClientPath = “C:\temp”;
OAttachment.Load(true, OAttachment.Name);
Let me know if this works.
Thanks,
Sumeet
LikeLike
Hi Sumeetji,
Could you please help me in downloading the test cases with steps
in excel format from HP ALM 12 for a selected domain/project/folder or all folders under a selected project.
It would of great help if you can provide any utility or working code
Thanks & Regards,
Marraju
LikeLike
Hi Sumeet,
Do you have the same code in VBA as you show us in c# ?
As I don’t know c#, it’s difficult for me to do a conversion…
Thanks in advance
Bernard
LikeLike
Check this repository
https://github.com/sumeet-kushwah/ALM_OTA_Wrapper/blob/master/ALM_Wrapper/Test.cs
LikeLike
I do get ALM connected. Where do I copy the download attachments code? Thanks for your help
LikeLike