Finally found the answer to how to Write to Test Resources. It's possible to use the QC OTA APIs to export it to QC. I made a function for loading and saving test recourses to and from QC.
Update 1
Added code for checking in and out of QC with comment
Update 2
Changed LoadResource function so it uses DownloadResoruce method from the API. Works much better that way.
Option Explicit
Function LoadResource(ResourceName)
Dim Resource, TempFolder
' Setting Temp Folder
TempFolder = environment("SystemTempDir")
' Load Resource
Set Resource = GetResource(ResourceName)
' Download Resource To Temp, The Entire Data Table is Downloaded
Resource.DownloadResource TempFolder, True
DataTable.AddSheet(SheetName)
DataTable.Import TempFolder & "\" & Resource.Filename
End Function
Function SaveResource(ResourceName)
' Dim values
Dim Connection, TempFolder, ResourceFactory, ResourceList, Resource, ItemCount, CurrentItem
' Create a Connection To QC
Set Connection = QCUtil.QCConnection
' Setting Temp Folder
TempFolder = environment("SystemTempDir")
' Create Resource Obejects
Set ResourceFactory = Connection.QCResourceFactory
Set ResourceList = ResourceFactory.NewList("")
Set Resource = Nothing
' Loops through all items and returns the correct one
For ItemCount = 1 To ResourceList.Count
CurrentItem = ResourceList.Item(ItemCount).Name
If UCase(CurrentItem) = UCase(ResourceName) Then
Set Resource = ResourceList.Item(ItemCount)
End If
Next
Set ResourceFactory = Nothing
Set ResourceList = Nothing
Resource.VC.CheckOut ""
' Export Datatable to Temp Directory
Datatable.Export TempFolder & "\" & Resource.Filename
' Upload Datatable in Temp to Resources Folder
Resource.UploadResource TempFolder, True
Resource.VC.CheckIn "Automated check-in from QTP by SaveResource"
Set Resource = Nothing
End Function
Function LoadResource(ResourceName)
Dim Resource, TempFolder
' Setting Temp Folder
TempFolder = environment("SystemTempDir")
' Load Resource
Set Resource = GetResource(ResourceName)
' Download Resource To Temp, The Entire Data Table is Downloaded
Resource.DownloadResource TempFolder, True
DataTable.AddSheet(SheetName)
DataTable.Import TempFolder & "\" & Resource.Filename
End Function
Function SaveResource(ResourceName)
' Dim values
Dim Connection, TempFolder, ResourceFactory, ResourceList, Resource, ItemCount, CurrentItem
' Create a Connection To QC
Set Connection = QCUtil.QCConnection
' Setting Temp Folder
TempFolder = environment("SystemTempDir")
' Create Resource Obejects
Set ResourceFactory = Connection.QCResourceFactory
Set ResourceList = ResourceFactory.NewList("")
Set Resource = Nothing
' Loops through all items and returns the correct one
For ItemCount = 1 To ResourceList.Count
CurrentItem = ResourceList.Item(ItemCount).Name
If UCase(CurrentItem) = UCase(ResourceName) Then
Set Resource = ResourceList.Item(ItemCount)
End If
Next
Set ResourceFactory = Nothing
Set ResourceList = Nothing
Resource.VC.CheckOut ""
' Export Datatable to Temp Directory
Datatable.Export TempFolder & "\" & Resource.Filename
' Upload Datatable in Temp to Resources Folder
Resource.UploadResource TempFolder, True
Resource.VC.CheckIn "Automated check-in from QTP by SaveResource"
Set Resource = Nothing
End Function
No comments:
Post a Comment