31.5.14

How to work with QC OTA - Example 1 - Get Defect ID and the size of Attachments in each defect

More often than not, we get weird requests, like getting a list of all the defects in QC and the size of attachments for each of them, but thankfully we have QC OTA to help us ease the pain. Use the below code to get a file with Defect ID and the size of all the attachments for them.


''Complete path of the file where the info from QC needs to be written
sQCLogFilePath = "C:\Automation\Attachments_List.csv"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(sQCLogFilePath)

''Getting the QC Connection Object. Refer earlier post about the implementation of this function
Set oALMConnObj = funcGetALMConnectionObj (sQCServer, sQCUsername, sQCPassword, sQCDomain, sQCProject)

''Getting the Bug Factory object
Set oBugFactory = oALMConnObj.BugFactory

''Defining the filters for the Defects
Set oBugFilter = oBugFactory.Filter
oBugFilter.Filter("BG_STATUS") = "Closed"
oBugFilter.Filter("BG_ATTACHMENT") = "Y"
oBugFilter.Filter("BG_DETECTED_BY") = "ASHISH.JAISWAL"

Set oBugList = oBugFilter.NewList

oFile.WriteLine("Defect ID" & "," & "Total Attachment Size")

For Each oBug In oBugList

        Set oBugAttachments = oBug.Attachments
        Set oBugAttachmentList = oBugAttachments.NewList("")

        iTotalAttachmentSize = 0
        For Each oBugAttachment In oBugAttachmentList
            iTotalAttachmentSize = iTotalAttachmentSize + oBugAttachment.FileSize
        Next

        oFile.WriteLine(oBug.ID & "," & iTotalAttachmentSize)

        Set oBugAttachmentList = Nothing
        Set oBugAttachments = Nothing

Next

Set oFile = Nothing
Set oFSO = Nothing
Set oBugFilter = Nothing
Set oBugFactory = Nothing
Set oALMConnObj = Nothing

No comments:

Post a Comment