hp-ufthp-alm

Use files from ALM as input for upload test


I try to store test files (pdf, docx, jpg) in ALM and use those as input files for upload tests. I am not sure, how could I copy files to ALM and after that how are these accessible from UFT.


Solution

  • There are lot of examples available online

    Function get_ALM_Resources(gstr_FrameWorkPath,gstr_Resourcename,gstr_Foldername)
        'Dowload files from ALM TestResource
    
        Set objqcConn = QCUtil.QCConnection
        Set lobj_Resource = objqcConn.QCResourceFactory
        Set lobj_Filter = lobj_Resource.Filter
    
        lobj_Filter.Filter("RSC_FOLDER_NAME") = gstr_Foldername
        lobj_Filter.Filter("RSC_FILE_NAME") = gstr_Resourcename
        Set lobj_ResourceList = lobj_Filter.NewList
        If lobj_ResourceList.Count <>0 Then
            Set lobj_oFile = lobj_ResourceList.Item(1)
            lobj_oFile.FileName = gstr_Resourcename
            lobj_oFile.DownloadResource gstr_FrameWorkPath, True
        End If  
    End Function
    

    PS: Credits https://github.com/mvlaxminarayan/Learn/blob/5c19b26c2361494b5cb961c36b274cfc937bb137/WMOS_FRAMEWORK/Function_libs/ALM_Component_Library.qfl

    Public Function fn_QCDownloadResource(sFileName, sDestination)  
        Dim objQC, objRes, objFilter, objFileList, objFile, sFilterPair, iCount
        If Not QCUtil.IsConnected Then  
            Exit Function
        End If  
        Set objQC = QCUtil.QCConnection
        Set objRes = objQC.QCResourceFactory
        Set objFilter =  objRes.Filter
        objFilter.Filter("RSC_NAME") = """" & Cstr(sFileName) & """"
        Set objFileList = objFilter.NewList
    
        If sDestination = "" Then
            sDestination = sDestination
        End if      
        If objFileList.Count = 1 Then
            Set objFile = objFileList.Item(1)
            objFile.FileName = sFileName & ".xlsx"
            objFile.DownloadResource sDestination, True   
        End If
        Set objQC = Nothing
        Set objRes = Nothing
        Set objFilter = Nothing
        Set objFileList = Nothing
        Set objFile = Nothing
    End Function
    

    PS: Credits https://github.com/PlusAutomationIkea/PlusAutomationSuite/blob/7489d362f0fcfef657da5f3284c830f84484eb51/FunctionLib/ALMHelper.qfl

    Function DownloadQCAttachment(strQCDir, strFileName, strTargetPath)
    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
    
        Set objFolder = QCUtil.QCConnection.TreeManager.NodeByPath(strQCDir) 
        Set objAttachmentList = objFolder.Attachments.NewList("") 
    
        For Each objAttachment In objAttachmentList 
            If InStr(1, objAttachment.DirectLink, strFileName, 1) > 0 Then
                Set objExtStorage = objAttachment.AttachmentStorage 
                objAttachmentName = objAttachment.DirectLink
                objExtStorage.Load objAttachmentName, true
                objFSO.MoveFile objExtStorage.ClientPath & "\" & objAttachmentName, strTargetPath & "\" & Split(objAttachment.Name, "_")(UBound(Split(objAttachment.Name, "_")))
                Exit For
            ElseIf strFileName = "" Then
                Set objExtStorage = objAttachment.AttachmentStorage 
                objAttachmentName = objAttachment.DirectLink
                objExtStorage.Load objAttachmentName, true
                objFSO.MoveFile objExtStorage.ClientPath & "\" & objAttachmentName, strTargetPath & "\" & Split(objAttachment.Name, "_")(UBound(Split(objAttachment.Name, "_")))
            End If
        Next
    
        Set objFSO = Nothing
    End Function
    

    PS: Credits https://github.com/Pradeep-ML/MobileLabsAutomationFramework/blob/248cd135848b5e159c770ab19ec73b7e981a9aad/FunctionLibraries/LoadTesting.qfl