Software Testing

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

By Test Guild
  • Share:
Join the Guild for FREE
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 = 

 oCurrentResources.Item(iNowResourceNum).Name
 
   if UCase(nowResource) = UCase(QcResourceName) then

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


Next

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

 oNewResource.ResourceType = "Test Resource" 
 oNewResource.Post
   
 oNewResource.UploadResource fileToSavePath, True
 
Else
  
 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"}

What is Behavior Driven Development (An Introduction)

Posted on 03/21/2024

Love it or hate it—Behavior Driven Development is still widely used. And unfortunately ...

What is ETL Testing Tutorial Guide

Posted on 11/29/2022

What is ETL Testing An ETL test is executed to ensure that data ...

Open Test Architecture How to Update a Test Plan Field (OTA)

Posted on 11/15/2022

I originally wrote this post in 2012 but I still get email asking ...

Discover Why Service Virtualization is a Game-Changer:  Register Now!