Download UFT script from ALM

Usually we use ALM to manage our test cases, test script and resource files, which works very well, but when we consider to host the script in git, we have to download them to local and commit to git.

In this exercise, I try to download UFT scripts and resource files in UFT with using ALM OTA , the OTA api reference can be found here, and here is the code.


Dim locPath
locPath= "c:\uft\script" 

DownloadTestsFromALM(locPath)
DownloadResourceFromALM(locPath)

Function DownloadTestsFromALM(SaveToFolderPath)

	Dim qcCon, testList, testStorage
	Set qcCon= QCUtil.QCConnection 
	If qcCon.ProjectConnected Then 
	
		Set testFilter = qcCon.TestFactory.Filter
		testFilter.Filter("TS_TYPE") = "QUICKTEST_TEST"
		Set testList = qcCon.TestFactory.NewList(testFilter.text)
		
		For each t in testList 
			Set testStorage= t.ExtendedStorage 
	        testStorage.ClientPath= SaveToFolderPath&"\" & t.Field("TS_SUBJECT").Path & "\" & t.Name
			
			on error resume next
			testStorage.Load "Action0\*.*, Action1\*.*, Action2\*.*, Action3\*.*, Action4\*.*, Action5\*.*, default.cfg, default.usp, Default.xls, Parameters.mtr, Test.tsp, *.usr", True 
			
	        if Err.Number <> 0  then
	           reporter.ReportEvent micWarning, t.Field("TS_SUBJECT").Path & "\" & t.Name & " -- File download fFAILED. error:=" &  Err.Description,""
	        else
	           reporter.ReportEvent micPass, t.Field("TS_SUBJECT").Path & "\" & t.Name & " -- File download successful.", ""
	        end if
		Next
	End If
	
	Set qcCon= Nothing
	Set testList= Nothing
	Set testStorage= Nothing

End Function


Function DownloadResourceFromALM(SaveToFolderPath)
	
	Dim qcCon,CurrentResObj,ObjResFactory,ResObjList
	
	Set qcCon = QCUtil.QCConnection
	Set ObjResFactory = qcCon.QCResourceFactory
	Set ResObjList = ObjResFactory.NewList("")
	
	For each CurrentResObj in ResObjList 
	
		on error resume next
		CurrentResObj.DownloadResource SaveToFolderPath& "\" & CurrentResObj.path & "\" & CurrentResObj.Name,True

        if Err.Number <> 0  then
           reporter.ReportEvent micWarning, CurrentResObj.path & "\" & CurrentResObj.Name & " -- File download FAILED. error:=" &  Err.Description,""
        else
           reporter.ReportEvent micPass, CurrentResObj.path & "\" & CurrentResObj.Name & " -- File download successful.", ""
        end if
   
	Next
	
	Set ResObjList = Nothing
	Set CurrentResObj = Nothing
	Set ObjResFactory = Nothing 
	Set qcCon = Nothing

End Function