Downloading Attachments from ALM/QC Defect Module

Introduction

HP ALM is a tool developed by HP, for managing the quality of the softwares. There are several modules available in ALM, and most of them (like defects, tests etc.) will allow uploading the attachments to it. At times either for analysis or for migration purpose we will need to download the bulk attachments from QC. In this post, we will see how to download attachments from different modules from QC. Code is written in C# and can be easily converted to any other language.

Downloading Attachments

For downloading attachments from defects module, we will first have to create ALM Connection object which is described here.

After you have successfully created the Object of TDConnection, then Copy the following function into your code execute the scripts, all of the defects with attachments will be downloaded in the desired folder.


public static Boolean DownloadDefectsAttachments(String AttachmentDownloadPath)

{

//OQConnection is the ALM Connection Object

TDAPIOLELib.BugFactory OBugFactory = OQConnection.BugFactory as TDAPIOLELib.BugFactory;

TDAPIOLELib.TDFilter OTDFilter = OBugFactory.Filter as TDAPIOLELib.TDFilter;

TDAPIOLELib.List OBugList;

TDAPIOLELib.AttachmentFactory OAttachmentFactory;

TDAPIOLELib.ExtendedStorage OExtendedStorage;

Console.WriteLine("Downloading attachments for the Defects : " + 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["BG_ATTACHMENT"] = "Y";

OBugList = OBugFactory.NewList(OTDFilter.Text);

foreach (TDAPIOLELib.Bug OBug in OBugList)

{

if (OBug.HasAttachment)

{

Directory.CreateDirectory(AttachmentDownloadPath + "\\" + OBug.ID.ToString());

Console.WriteLine("Downloading attachments for the Defect : " + OBug.Summary.ToString());

OAttachmentFactory = OBug.Attachments;

//Download defect attachments

foreach (TDAPIOLELib.Attachment OAttachment in OAttachmentFactory.NewList(""))

{

OExtendedStorage = OAttachment.AttachmentStorage;

OExtendedStorage.ClientPath = AttachmentDownloadPath + "\\" + OBug.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 it works

For downloading the attachments from defects we will use the following objects

  • BugFactory : Bug Factory object is the Bug manager class of OTA API. This can be used for creating and managing the defects.
  • Bug : Bug is the actual defect object which will represent a single defect 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 defect, first we have to filter the defects with attachments; otherwise, it might take a lot of time for the bigger projects to navigate through all of the defects.

ALM will store value ‘Y’ in the field “BG_ATTACHMENT” and we will use this field to filter the defects with attachments.


OTDFilter["BG_ATTACHMENT"] = "Y";

OBugList = OBugFactory.NewList(OTDFilter.Text);

After the execution of the above statements, we will get the list of defect object with attachments in OBugList object.

Now, for each of the listed defects, we will get the attachments object like this


OAttachmentFactory = OBug.Attachments;

And then we will download the attachments using the extended storage objects.

Advertisements

One response to “Downloading Attachments from ALM/QC Defect Module

  1. Pingback: DOWNLOADING ATTACHMENTS FROM ALM/QC, Tests and Design Steps module | Automation Insights·

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s