How to use QTP to save and retrieve a Quality Center Test Resource

Software Testing Published on:
Modern Testing

Sometimes in your QTP script you need to save and retrieve data stored in a text file across multiple machines. Quality Center has a ‘resource' module where you can store a resource like a text file. I use this functionality so much that  I created two QuickTest Professional functions specifically for this:

  • QcSaveToResource – This function will save a text file from a local machine to an existing resource in QC
  • QCGetResource – This function will copy a file stored in QC to a local drive.

( Also check out my video : How to get a QC resource using QTP with OTA)

How to save a text file to QC (QcSaveToResource)

The following code will save a text file from a QuickTest Pro lab machine to an existing ‘Test Resource' in QC's Test Resource module:

QcSaveToResource "Joe","qcresourcetest.txt","C:\QTPAUTOMATION\DATA","",""

How to get a Quality Center test resource and save to a local dir (QCGetResource)

QCGetResource "qcresourcetest.txt","C:\Temp"

QTP QC function that you can use!

'@Function Name: QCSaveToResource

'@Documentation Saves a text file to the QC Test Resources module

'@Created By: Joe Colantonio

'@Return Values: NONE

'@Example: QcSaveToResource "Joe","qcresourcetest.txt","C:\QTPAUTOMATION\DATA","",""

Function QCSaveToResource(QcResourceName,fileNameToSave,fileToSavePath,resourceType,opt)

'Upload a resource


Set qcConn = QCUtil.QCConnection

Set oResource = qcConn.QCResourceFactory

Set oCurrentResources =oResource.NewList("")

Set oNewResource = Nothing
resourceCount = oCurrentResources.Count
For iNowResourceNum = 1 To resourceCount
nowResource = 

   if UCase(nowResource) = UCase(QcResourceName) then

    Set oNewResource = oCurrentResources.Item(iNowResourceNum)
    resourceFound = "True"
   end if


If resourceFound = "True" Then
 oNewResource.Filename = fileNameToSave

 oNewResource.ResourceType = "Test Resource" 
 oNewResource.UploadResource fileToSavePath, True
 reporter.ReportEvent micFail,"Did not find a resource in the Test Resource module named " & QcResourceName,"Verify that a resource exist in the QC Test Resource module!"

End If

Set oCurrentResources = Nothing

Set oResource = Nothing

End Function
'@Function Name: QCGetResource

'@Documentation Saves a text file from a QC Test Resource to a local dir

'@Created By: Joe Colantonio

'@Return Values: NONE

'@Example: QCGetResource "qcresourcetest.txt","C:\Temp"

Function QCGetResource(resourceName,saveTo)
Set qcConn = QCUtil.QCConnection

Set oResource = qcConn.QCResourceFactory

Set oFilter = oResource.Filter
  oFilter.Filter("RSC_FILE_NAME") = resourceName

Set oResourceList = oFilter.NewList

If oResourceList.Count = 1 Then

  Set oFile = oResourceList.Item(1)
oFile.FileName = resourceName
oFile.DownloadResource saveTo, True

End If

Set qcConn = Nothing

Set oResource = Nothing

Set oFilter = Nothing

Set oFlieList = Nothing

Set oFile = Nothing
End Function
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
Modern Testing

Software Quality Management in TestOps

Posted on 08/31/2022

Quality is most likely foremost in your mind when building a new product, ...

Software Testers Directory: 14 Best Software Testing Tools in 2022

Posted on 05/20/2022

Software testing is a process in software development. It helps developers find and ...

The Ultimate Mobile Testing Guide: 11 Tips to Test Your App Effectively

Posted on 03/21/2022

Are you a tester who wants to excel in the team? Or a ...