Overview
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




{ 60 comments… read them below or add one }
Can you let me know how to download all the resources that are stored in the quality center ‘test resources’ folder to local machine using OTA script?
@1415: Hi – When you say all resource do you want everything – including function libraries and object repositories? I’m not 100% sure how to do this. I have not tried to do this yet but you should be able to step-thru and modify my code example to do this. Also HP’s KB has an article that shows how to download resources using a custom DLL that may be better for your situation. Check HP article KM838074 .
I want to upload a file into the resource without checking for existance of the file in the test resources module.
Could please let me know the same on how to do it.
Regards,
S.Niranjan
Hi Joe
I encounter an issue while save my resoucre file to QC. It alerts that “The external resource could not be uploaded to the QualityCenter server repository”. Do you know the root cause of the problem?
@William: Hi William – I’ve seen this error if I try to save a resource name that is not unique or it could be caused by a type/spelling error.
Hi Joe
Many thanks for your replying! I used the full file path like “C:\Temp\test.vbs” as fileToSavePath parameter value. However, while I was using “C:\Temp\” as fileToSavePath value, the error message was not displayed, but the attachment is blank.
Hi William,
I agree, i also have the same issue. the attachment is not uploaded to QC resource….
Balveer » Hi – can you take a look at this video ( http://www.youtube.com/watch?v=OkVhSwhLw1w) and let me know what you are doing differently? Cheers ~Joe
Hi Joe,
I am looking for help generating automatic test execution status reports from QC. Can you suggest how I can do it? I am not a coder and so need step by step instructions. I would really appreciate quick help please. Also I have used many of your videos on Service test and load runner that you posted on youtube. I found it very useful. Thanks.
Asheena
Asheena Andrews » Hi Asheena – my team just uses the standard QC Analysis reports. To get the info we need, in the test lab, we usually set the QC set filter option first. Is there a specific issue you are having?
Hi Joe, How do I get the file from other places like Test Plan tab or do the files have to exist in the Resources tab? We use QC 9.2 and do not have Resources tab.
Are there any other places that we can save the files in QC and retrieve using QTP?
With the existing code, qcConn.QCResourceFactory displays error saying — ‘Object doesn’t support this property or method’
THanks
Kumar S » Hi Kumar – if you are running your QTP test in a test set in QC you can save and retrieve files in the test lab’s ‘Attachments’ tab. I can send you a code example of this if you want. Let me know.Cheers~Joe
Hi Joe, This is exactly what I want to do. We have a test set with different test scripts and I want to have some attachments (input xml files) within this test set that I would like to read from each script and use appropriate input data. Any sample code would be awesome.
Thank you
Hi Joe,
When I try to upload one Text file. I’m getting below errors.
Failed to Post Simple Key Entity
Line (49): “oNewResource.Post”.
When I click on “Retry”. I’m getting below error
The resource must be assigned a name before it can be uploaded or downloaded from the Application Lifecycle Management Platform.
Line (50): “oNewResource.UploadResource fileToSavePath, True”.
Can I know why actually this error is poping up.
Actually, my requirement is to upload Result Excel files into specific Folder (say “Results” folder) in Resources or TestPlan tab.
Can anybody know the above procedure?
regards,
Baba Fakruddin D
Baba » Hi Baba – I just tried the code that I posted against ALM11 and it worked for me. In ALM do you have a Results resource setup under Resources? Can you send me exact code you are using? Thanks~Joe
Hello Joe,
I was wondering if it would be possible to save a file to the Attachments section in a test case(Test Name)? ex: Root\folders\Test Set\Test Name
We run our tests on another stand alone machine that has QTP. And using QTP to update QC fields. When the test fails I want to create a txt file with the failure results and save the file to the attachments for that test case via QTP to QC.
Is this possible?
Any tips or suggestions are much appreciated!
Thanks,
Kari
Kari » Hi Kari – I have another blog post that I believe will help you – How to attach a file to a testiest attachment tab. Please let me know if you have any more question or issues with this. Cheers~Joe
Hello,
I was wondering if it is possible to the same thing but for downloading a resource that is in “Check Out” or to an older version of a resource? (i have versioning enabled in my project)
Thanks,
Achraf » Hi Achraf – Unfortunately I don’t know. I would try but I don’t have a QC environment that uses version control. Please let us know if you figure it out. Cheers~Joe
Hello again,
For a file in checkout, DownloadResource already does that automatically (it downloads the version in checkout by the user if possible)
For downoading older versions of the file, the only way i found, was to build the full physical path to the version of file i want, and then use the TDConnection.ExtendedStorage object to download it. (however building the path is a bit tricky and requires much longer to explain how it’s done)
Thanks and regards,
Hi Joe,
In following code I am trying to upload excel file to Data table resource in Quality Center. But I am getting two errors as following.
1) on line “oRes.Post”, I got error “Failed to Post simple Key entry”.
2) on line “oRes.UploadResource “, I got error “The external resources could not be uploaded to the Quality Center Server Repository ”
============================================
Code
============================================
Set QCResource =
QCUtil.QCConnection.QCResourceFactory
Set NewQCResource = QCResource.NewList(“”)
For i=1 to NewQCResource.Count
If NewQCResource(i).Name = “InputDataFile” Then
Set oRes = NewQCResource(i)
Msgbox oRes.FileName
Exit For
End If
Next
oRes.FileName = “InputData”
oRes.ResourceType = “Data table”
oRes.Post
oRes.UploadResource “C:\InputData.xls”,True
Set oRes = Nothing
Set NewQCResource = Nothing
Set QCResource = Nothing
John Pellen » Hi John – Sorry, I have not see this issue before and I’ve been unable to repro on my machine. Have you figured it out yet? Anyone else have any ideas?
Hi Joe,
Big thanks for the QTP Paches repository in your Blog.I recently downloaded QTP-00092 Patch for firefox 9 and 10 support.
My question is how to test a webEdit object by Boundary Value Analysis using QTP(Especially for maximum length+1 case).
suppose my WebEdit maxlength is 10 characters and if want to test it for 11 characters.
If i use .Set method QTP throwing an error as Parameter is Incorrect.
If i use Type Method,I’m getting the error as object does’nt support this method.
So how should we test with QTP in this particular negative scenario????????????
Thanks in-advance
vasu » Are the errors QTP errors or application under test errors/dialogs? I would think that either set or type would work for you- have you tried sendkeys?
Hi Joe.we are using QTP-11.00 and QC(ALM)-11.00.Recently we integrated QTP and QC after installing QC-QTP addin and QTP-11.00 addin and checked the checkbox in “Tools<Options,Run<Allow other HP products to run tests and components" in QTP.We saved our script in TestPlan module (subject<some folder) from QTP.When we click on TestScript tab in TestPlan we are getting QC dialog box errors as
"Attempted to read or write protecte memory.This is often an indication that other memory is corrupt."If we click on OK button then again we are getting dialog as
"External component has thrown an exception."we are unable to view script in QC.
Plz suggest me any solution regarding this issue.
Environment-windows 7
Thanks in-advance
I am also getting the same error.
PLease help if somebody has a solution.
Hey, Joe,
I am using vapi xp vbscript test to upload .xls file to the QC Test Resources. But after running it I got error: “The external resource could not be uploaded to the QualityCenter server repository. ” (there are no duplicate names in resources). Then I checked QC Test Resources and there was file name inserted, but download button was disabled. I can’t figure out what is wrong. I see others were also getting same error. So maybe you or someone else have figured out what’s wrong? It would help me a lot in my job.
BR,
Lina
Lina » HI Lina the only time I’ve seen this error is when I’m using the wrong path or resource name. Anyone else have any ideas?
How to get min length of a webedit using QTP(VB scripting) ???
just like getting max length by
maxL=Browser(“”).page(“”).Webedit(“”).getroProperty(“max length”)
@ John Pellan – on line “oRes.UploadResource “, I got error “The external resources could not be uploaded to the Quality Center Server Repository ”
Resolution :
Remove backslash ‘\’ for uploadfolder name and verify that Upload file name is the same as it exists on local machine
Hi!
I want to know how can I call a .bat file that is located on my Resources tab in ALM from my QTP test? Is this possible?
This .bat file call the application I want to test with specific login information according to the test that is executed, or at least that’s the idea.
How can I call this . bat file from within QTP script?
Any Idea will be appreciated.
Fulge » You should be able to save a.bat file to a test resource in ALM and call it using the code I posted. Are you having an issue with the code?
Hi Joe,
Thanks for the excellent post.
In addition, How would I add a ‘Resource Folder’ through API? I have tried something like this,
Set resFolder = tdc.QCResourceFolderFactory
resFolder.AddItem (“test_fol”)
but it doesn’t create folder. Can you please help how to create resource folder throught API?
Venky » Hi Venky thanks for the question! I just created a post to answer your question How to add a new folder to the QC Resource Module Using OTA. Hope it helps. Cheers~Joe
Many thanks Joe. Another useful article from you. Excellent!
Venky » Cool – thanks Venky!
I am having a project requirement , which I need to retrieve defect time stamp from HP Quality center to check, time of arrival of the defect.Please send me the code otherwise I wont get appraisal this time. I have given word to my manager.
I’m also getting the “The resource must be assigned a name before it can be uploaded or downloaded from the Quality Center server.” error when I upload.
TDAPIOLELib.QCResourceFactory resFact = (TDAPIOLELib.QCResourceFactory)connection.QCResourceFactory;
TDAPIOLELib.IResourceStorage res = (TDAPIOLELib.IResourceStorage)resFact[id];
res.UploadResource(file, true);
any suggestions?
I wasn’t setting the “resource.FileName” property of the resource before I was trying to upload. That specific error went away but now I’m getting “The external resource could not be uploaded to the QualityCenter server repository.”
Drew » Drew finally figured this out. Here is his code – Thanks Drew for sharing your resolution!
/// Updloads a file a specified resource
///
///
/// The ID of the file to upload toTrue if successful
/// The local path of the file to upload
///
public bool Upload_Resource(int FileId, string ResourcePath)
{
try
{
TDAPIOLELib.QCResourceFactory resFact = (TDAPIOLELib.QCResourceFactory)connection.QCResourceFactory;
TDAPIOLELib.QCResource resource = (TDAPIOLELib.QCResource)resFact[FileId];
string[] FilePath = ResourcePath.Split(‘\\’);
TDAPIOLELib.IVersionControl _ivc;
TDAPIOLELib.IVersionedEntity _ive;
_ive = (TDAPIOLELib.IVersionedEntity)resource;
_ivc = (TDAPIOLELib.IVersionControl)_ive.VC;
_ivc.CheckOut(“Uploading file to resource.”);
try
{
resource.FileName = FilePath[FilePath.Length - 1];
resource.ResourceType = “Test Resource”;
resource.Post();
TDAPIOLELib.IResourceStorage res = (TDAPIOLELib.IResourceStorage)resource;
res.UploadResource(ResourcePath.Replace(FilePath[FilePath.Length - 1], “”), true);
_ivc.CheckIn(“Uploading file to resource.”);
return true;
}
catch
{
_ivc.UndoCheckout();
return false;
}
}
catch { return false; }
}
hi Joe,
:):)
I am also getting error “failed to post simple key entity” oNewResource.post . I am using exactly the same code written by you above . Can you please help me . Can you tell me the probable reasons for this .
Many many thanks in adavance
somanath » Hi – not sure why this is happening — it does work for me. Anyone else have any ideas?
Hi There,
I have to download particular folder in QC resources which contain .vbs file, which related to my automation suite however I am wondering if you can help me in this.
Thanks,
Cha » The code should work with resources that contain .vbs files. What issues are you having?
Hi Joe,
Thanks for reply.
Function which I used “QCGetResource” downloads only 1 file at a time which is been passed, i need to download entire folder from resouces tab,
However really appriciate if you would provide code snippet for that.
Thanks
Hi Joe, Good day….
In our organization we are planning to move all our scripts, Library files, repository, data files and xml files to Test Resource folder in QC. Can you please let me know how to call these file from QC in the script???
Thank you for your help.
Sri » Hi Sri – you should be able to associate your function libraries from QTP>File>Settings and in the Test Settings click on Resources. You can point to a library in QC and associate it with your test script. For Object Repository you can do the same by going into QTP’s menu Resources>Associate Repositories and select your OR’s stored in QC. Is this what you are looking for?
Joe… Thank you for your reply.
I need to import library, excel and repository in run time. I am working on a very big application and it’s an event driven script. So I need to call the required function during runtime.
Sri » Hi Sri – You could also use the ExecuteFile statement to call a function library at run time.
Hello Joe,
Thanks a lot for such a wonderful site. I’m also facing the same issue what Sri is referring to.. Can you please assist with the code for the following..
1. To connect qtp and qc during run time.
2. To import library, excel, repository during run time
3. To add the test cases to test lab during run time
4. To exectue the test scripts added in test lab
5. To store and view the result.
Thanks a ton for your suppport.
Cheers,
Santhosh.
Santhosh » Hi Santhosh:
1. set tdc = createobject(“TDApiOle80.TDConnection”)
tdc.InitConnectionEx “http://qcURL/qcbin/”
tdc.login “yourUserName”,”yourPassword”
tdc.Connect “yourDomain”,”yourProject”
2. ?
3. http://go-gaga-over-testing.blogspot.com/2012/03/qc-ota-test-lab.html
4. http://www.joecolantonio.com/2011/11/30/qc-qtp-how-to-schedule-a-recurring-test-set/
5. ?
Joe, I am attempting to use the code included in this blog post and
am wondering what the filter would be to search by resource name instead of file name. I have several resources that contain the same filename (i.e. different copies of the same file listed under different resource names).
PS. It appears that all resources are returned when it fails to find the one you set in the filter. In case anyone is wondering why they are getting back a large number of resources instead of just 1.
Figured it out. Looks like it’s nice and obvious. Just “RSC_NAME”. I was unable to find a list of possible filter values in the OTA documentation. Where can I get one?
Upload worked Nicely… Thanks for the help… really appreciate it…
Vivek Gupta » Cool!
Hi Joe,
Very useful post. One question though – here “oFilter.Filter(“RSC_FILE_NAME”) = resourceName” filters by resource name. What other filters are available and where can I find the documentation for these. It would help me a lot if I could also filter on the resource’s parent folder.
Please advise.
Regards,
Hara Prasad
Hara –
Check the OTA reference for for TDFilter, you’ll see: “The values can be constants, special tokens such as “[Today]“, “[PreviousWeek]“, or “[NextYear]“, or folder names, such as “^Subject\LinkFolder^”. Use the set filter dialog in the the relevant module of the ALM user interface to explore the possibilities.”
So open the Filter dialog under resources, set up the filter that you’d want, and then you can Copy/Paste the actual filter. It contains what you need, for example, when I set up a filter to give me the Test Resource with folder name = My Host Names, it looks like:
[Filter]{
TableName:RESOURCES,
ColumnName:RSC_FOLDER_NAME,
LogicalFilter:0000019\^Resources\My Host Names^,
VisualFilter:0000019\^Resources\My Host Names^,
NO_CASE:
}
Also see Joe’s link:
http://www.joecolantonio.com/2012/11/15/almqc-how-to-update-a-test-plan-field-using-ota/
Which gives an easy overview of all the field names in all components using Project Customization view.
Is there is a API to connect and extra data from Performance Center(subset of ALM) using QTP. I need to read few columns within the test lab during run time.
Thank You,
Srini
Srini » Hi Srini – I’m still researching this. I don’t have Performance Center installed so I’m not sure. I know that ALM 11 have a REST api but I don’t think it touches the performanace center info. Does anyone else know if this is possible?