Highlighted
Respected Contributor.
Respected Contributor.
2311 views

Export and import excel from UFT to HP ALM

Hi everyone,

I need to upload an excel from UFT to ALM and then, in another test, I need to import this file from ALM to UFT, I am reading about that in forums and seeing some codes but don't work!

Thanks in advance,

Sam

0 Likes
3 Replies
Highlighted
Respected Contributor.
Respected Contributor.

Re: Export and import excel from UFT to HP ALM

A teammate told me this is not possible, anyone knows if this is true?

It's very important to my if there is some way to do that!

Thanks very much!

Sam

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: Export and import excel from UFT to HP ALM

Hi, Sam

It is not possible manually to perform the importing in DT pane. However, you can use the following script to do so:

  • Import "[ALM\Resources] Resources\<Path>\<DT resource>
  • Import "[ALM] Subject\<Path to the Test>\<attachment>.xls"

Therefore, it is ok to import DT from ALM.

Thanks.

James

Highlighted
Frequent Contributor.. Frequent Contributor..
Frequent Contributor..

Re: Export and import excel from UFT to HP ALM

It's possible through the ALM API.

The code below tries to load the DataTable from the testset instance, fron the TestSet if not found, the TestSet folder if not found, the test istself, and if not foud, use the default datatable of the test.

'@Description Load a DataSheet (attached to TestInstance or TestSet or TestSet Folder or Test in Test Plan) into Test DataTable 
'@Documentation <strDataFileName> DataSheet Filename (with XLS / XSLX extension), <strDataSheetName> DataSheet to be loaded
Public Function LoadDataSheet(ByRef strDataFileName, ByVal strSourceDataSheetName, ByVal strTargetDataSheetName)
'  '--------------------------------------------------------------
' Purpose :
' ---------
' This function loads the DataTable sheet(s) from:
'  -1- From Current Test Instance if exist
'  -2- From Current TestSet if not exist in Crrent Test Instance
'  -3- From Test Set Folder if not exist in Test Set
'  -4- From Test in Test Plan if not exist in TestSet Folder
'
'  If DataTable contains other sheets, they are already loaded. !! BEWARE !!: the 1st sheet is loaded as the dtLocalSheet.
'
' Parameters :
'   - strDataFileName : Name of the file to be loaded WITH EXTENSION
'   - strDataSheetName : Name of the sheet to be loaded
'
' Return value :
'   - local File Name
'--------------------------------------------------------------
'
'-------------------------------------------------------------

  Dim strLogFileName, strInfoVersion, b_DataFileFound, i
  Dim strRunMode, strOrigin, localFile
  Dim oCurrentTest, oCurrentTSTestSet
'  =====  Create Log File  ===========
  strLogFileName = "loadDataSheet"
  strInfoVersion = "loadDataSheet"
' --- Log File
  CreateLogFile strLogFileName
   writeLogFile strLogFileName, " >>> Start log file for "& strInfoVersion
  writeLogFile strLogFileName, strInfoVersion & " - Init ==> Load File  ["& strDataFileName &"]"

'  On intercepte les erreurs
  On error resume next
  b_DataFileFound=false
  strRunMode = "Test"
'  -1- On va positionner la source en fonction du niveau d'execution : du TEST jusqu'au RUN
'  -1.0- Origine = "Test"
  strOrigin = "Test"
'  -1.1- Origine = "TEST"
  set oCurrentTest = QCUtil.CurrentTest 
  writeLogFile strLogFileName, strInfoVersion & " - Init ==> Current Test  ["& oCurrentTest.Name  &"]"
'  reporter.ReportEvent micDone, "Test Name", "["& oCurrentTest.Name &"]"
  If err.number = 0 Then
    strOrigin = "Test"
    strRunMode = "TestPlan"
  End If
  
'  -1.2- Origine = "INSTANCE DE TEST"
  set oCurrentTSTestSet = QCUtil.CurrentTestSetTest 
  writeLogFile strLogFileName, strInfoVersion & " - Init ==> Current TSTest  ["& oCurrentTSTestSet.Name  &"]"
'  reporter.ReportEvent micDone, "TSTestSetName", "["& oCurrentTSTestSet.name &"]"
  If err.number = 0 Then
    strOrigin = "TSTest"
    strRunMode = "TestSet"
  End If
  
  If strOrigin = "TSTest" Then
    writeLogFile strLogFileName, strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test Instance"
    Reporter.ReportEvent micDone,"##loadDataSheet", strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test Instance"
    localFile = GetAttachmentFromTestObject (oCurrentTSTestSet, strDataFileName, getTempFolder)
'=> Si pas trouvé, attaché au TestSet
    If instr(localFile,"["& strDataFileName &"] not found") >0 Then
      writeLogFile strLogFileName, strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test Set"
      Reporter.ReportEvent micDone,"##loadDataSheet", strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test Set"
      localFile = GetAttachmentFromTestObject (QCUtil.CurrentTestSet, strDataFileName, getTempFolder)
      strOrigin = "TestSet"
'=> Si pas trouvé : depuis le TestSet Folder
      If instr(localFile,"["& strDataFileName &"] not found") >0 Then
        writeLogFile strLogFileName, strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test Set Folder"
        Reporter.ReportEvent micDone,"##loadDataSheet", strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test Set Folder"
        localFile = GetAttachmentFromTestObject (QCUtil.CurrentTestSet.TestSetFolder, strDataFileName, getTempFolder)
        strOrigin = "TestSet Folder"
'        reporter.ReportEvent micDone,"Load from folder","file ["& localFile &"]"
      end if
    End If
  End If

'=> Si pas trouvé ou Run de type "Component "ou de type "Test" : depuis TEst dans le Test Plan
  If instr(localFile,"["& strDataFileName &"] not found") > 0 or strOrigin = "Test" Then
    writeLogFile strLogFileName, strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test ["& oCurrentTest.Name &"]"
    Reporter.ReportEvent micDone,"##loadDataSheet", strInfoVersion & " - Load ==> About to load  ["& strDataFileName  &"] from Test ["& oCurrentTest.Name &"]"
    localFile = GetAttachmentFromTestObject (QCUtil.CurrentTest, strDataFileName, getTempFolder)

  end if

'  ===  Chargement si trouvé
  If instr(localFile,"["& strDataFileName &"] not found") =0 Then

    ' - Get sheet count (in order to load main DataSheet, and subDataSheets (For lists)
    rc = OpenExcelFile(localFile, oWorkBook, oExcel, false)
    iSheetCount = oExcel.Sheets.Count
    ReDim preserve aSheetName(iSheetCount)
    For i = 1 To iSheetCount Step 1
      aSheetName(i) = oExcel.Sheets(i).Name
    Next
    oWorkBook.save
    oWorkBook.close
    oExcel.quit
'    DataTable.ImportSheet localFile,1, DtLocalSheet
'    writeLogFile strLogFileName, "  .. Sheet #[" & 1 & "] loaded in DataTable Sheet ["& aSheetName(1) &"]"
    ' --- Load a sheet identified by its number
    If IsNumeric(strSourceDataSheetName) Then
      If strSourceDataSheetName > iSheetCount Then
'        reporter.ReportEvent micWarning, "##loadDataSheet","DataFile [" & localFile &"] => Sheet #["& strSourceDataSheetName &"] doesn't exist ! Use sheet #1 => ["& aSheetName(1) &"]"
        reporter.ReportEvent micDone, "##loadDataSheet","DataFile [" & localFile &"] => Sheet #["& strSourceDataSheetName &"] doesn't exist ! Use sheet #1 => ["& aSheetName(1) &"]"
        writeLogFile strLogFileName, "  DataFile [" & localFile &"] => Sheet #["& strSourceDataSheetName &"] doesn't exist ! Use sheet #1 => ["& aSheetName(1) &"]"
        strSourceDataSheetName = 1
      End If
      strSourceDataSheetName = aSheetName(strSourceDataSheetName)
    else
    ' --- Load a sheet identified by its name
      bFOund = false
      For i = 1 To iSheetCount Step 1
        If compareString(aSheetName(i), strSourceDataSheetName) = 0 Then
          bFound = true
          Exit for  
        End If
      Next
      If bFound = false Then
'        reporter.ReportEvent micWarning, "##loadDataSheet","DataFile [" & localFile &"] => Sheet ["& strSourceDataSheetName &"] doesn't exist ! Use sheet #1 => ["& aSheetName(1) &"]"
        reporter.ReportEvent micDone, "##loadDataSheet","DataFile [" & localFile &"] => Sheet ["& strSourceDataSheetName &"] doesn't exist ! Use sheet #1 => ["& aSheetName(1) &"]"
        writeLogFile strLogFileName, "  DataFile [" & localFile &"] => Sheet ["& strSourceDataSheetName &"] doesn't exist ! Use sheet #1 => ["& aSheetName(1) &"]"
        strSourceDataSheetName = aSheetName(1)
      else
        strSourceDataSheetName = aSheetName(i)    
      End If
    End If
    ' --- Then, load the DataSheet
    DataTable.AddSheet strTargetDataSheetName
    DataTable.ImportSheet localFile,strSourceDataSheetName, strTargetDataSheetName
    writeLogFile strLogFileName, "  .. Sheet #["& strSourceDataSheetName &"(" & i & ")] loaded in DataTable Sheet ["& strTargetDataSheetName &"]"
    reporter.ReportEvent micDone, "##loadDataSheet","DataFile [" & localFile & "/" & strSourceDataSheetName &"] loaded into LocalSheet ["& strTargetDataSheetName &"]"
    writeLogFile strLogFileName, "  DataFile [" & localFile & "/"& strSourceDataSheetName &"] loaded into LocalSheet ["& strTargetDataSheetName &"]"
  end if
  LoadDataSheet = localFile

  writeLogFile strLogFileName, " <<< End Log file for " & strInfoVersion

End Function

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.