Monday, July 15, 2013

VB Script || QC Code || QTP || Upload an attachment file and Send attachment file in mail from test plan automatically.

Below is the code that i used for sending mail from Quality Centre to the recipient list.The attachment is sent from Test Plan.

FilePath = ""    'File Path where your file is located.

Call UpLoadAttachmentToQC(FilePath)        ' Call the function to upload the attachment

Function UpLoadAttachmentToQC(FilePath)

Set ObjCurrentTest = QCUtil.CurrentTest.Attachments 'Creating QC Util Object with attachment

Set ObjAttch = ObjCurrentTest.AddItem(Null)    'Object for Current Test Set

ObjAttch.FileName = FilePath        'Attaching the File in the Object

ObjAttch.Type = 1  

ObjAttch.Post    'Post your Attachment to the QC

ObjAttch.Refresh   'Refresh the Object

Set attachFact = QCUtil.CurrentTest.Attachments 

'Here i have created attachment factory object which is associated with QC and it will fetch all the attachment from the current Test Plan and store it in attachList array of element.

Set attachList = attachFact.NewList("")          
ReDim Preserve AttachmentList(attachList.Count - 1)

  Dim i
  i = LBound(AttachmentList)

'Running loop for each attachment and uploading them from QC to an array.

   For Each theAttachment In attachList
         AttachmentList(i) = theAttachment.ServerFileName
          i = i + 1

Dim fName

  For Each fName In AttachmentList
      MsgBox "The AttachmentList element is: " & fName

Mailto = "abc@domainname"

'Use the send mail method of Quality Centre to sent mail to the concerned authorities with Attachment list array.

QCUtil.QCConnection.SendMail Mailto,,,,AttachmentList

End Function


  1. Please provide me the VB script for uploading an attachment to Quality Center Test Lab without using QTP