Micro Focus QTP (UFT) Forums
Any option to copy/download from HPQC to local path...pls help - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Any option to copy/download from HPQC to local path...pls help (/Thread-Any-option-to-copy-download-from-HPQC-to-local-path-pls-help)



Any option to copy/download from HPQC to local path...pls help - remya - 11-30-2010

Hi,

There is one file(.jar file) as an attachment in a folder under Testplan tab in HPQC
I need to download this file from HPQC to local drive of our PC

is there any option to copy/move/download from QC to our local PC
by coding
or any option to run these (.Jar file) from QC path?????


pls reply me if anyone has solution for it..


Thanks

Remya


RE: Any option to copy/download from HPQC to local path...pls help - cdesserich - 12-02-2010

Here's a function to download attachments from QC. It will only work for attachments in the Test Plan module, but that should work for you.

Code:
'@Description Downloads specified attachment from QC. Specify the fully qualified QC path, ex. "Subject\Utilities\Test.txt". Returns the local file path.
Public Function LoadAttachment(ByVal attachmentPath)
    Dim node, attachmentFilter, attachmentList, attachment, nodePath, fileName
    
    nodePath = Left(attachmentPath, InStrRev(attachmentPath, "\") - 1)
    fileName = Right(attachmentPath, Len(attachmentPath) - InStrRev(attachmentPath, "\"))
    
    Set node = QCUtil.TDConnection.TreeManager.NodeByPath(nodePath)
    Set attachmentFilter = node.Attachments.Filter
    attachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & node.NodeID & "_" & fileName & "'"
    Set attachmentList = attachmentFilter.NewList
    
    If attachmentList.Count = 1 Then
        Set attachment = attachmentList.Item(1)
        
        'Create a dialog to show while attachment is loading if not running from QC
        If QcUtil.CurrentTestSet Is Nothing And QcUtil.CurrentRun Is Nothing Then
            Dim dialogForm, dialogStartPosition, dialogBorderStyle, dialogLabel, dialogFont, dialogContentAlign, hWnd, intPtrHWnd, qtpWnd
            Set dialogForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
            Set dialogStartPosition = DotNetFactory.CreateInstance("System.Windows.Forms.FormStartPosition", "System.Windows.Forms")
            Set dialogBorderStyle = DotNetFactory.CreateInstance("System.Windows.Forms.FormBorderStyle", "System.Windows.Forms")
            Set dialogLabel = DotNetFactory.CreateInstance("System.Windows.Forms.Label", "System.Windows.Forms")
            Set dialogFont = DotNetFactory.CreateInstance("System.Drawing.Font", "System.Drawing", "Microsoft Sans Serif", 11)
            Set dialogContentAlign = DotNetFactory.CreateInstance("System.Drawing.ContentAlignment", "System.Drawing")
            dialogForm.Width = 280: dialogForm.Height = 100: dialogForm.ControlBox = False: dialogForm.StartPosition = dialogStartPosition.CenterScreen
            dialogForm.FormBorderStyle = dialogBorderStyle.FixedDialog: dialogForm.Text = "Downloading Attachment From Quality Center..."
            dialogLabel.Width = 260: dialogLabel.Height = 80: dialogLabel.Top = 0: dialogLabel.Left = 10: dialogLabel.Font = dialogFont
            dialogLabel.TextAlign = dialogContentAlign.MiddleCenter: dialogLabel.Text = "Downloading " & fileName & " From Quality Center, Please Stand By..."
            dialogForm.Controls.Add dialogLabel
            hWnd = Window("RegExpWndTitle:=QuickTest Professional").GetROProperty("hWnd")
            Set intPtrHWnd = DotNetFactory.CreateInstance("System.IntPtr", "Mscorlib", hWnd)
            Set qtpWnd = DotNetFactory.CreateInstance("System.Windows.Forms.NativeWindow", "System.Windows.Forms")
            qtpWnd.AssignHandle intPtrHWnd
            dialogForm.Show qtpWnd: dialogForm.Refresh()
        End If
        
        'Load attachment
        attachment.Load True, ""
        
        'Get rid of the dialog if not running from QC
        If QcUtil.CurrentTestSet Is Nothing And QcUtil.CurrentRun Is Nothing Then
            dialogForm.Close: dialogForm.Dispose
            Set dialogContentAlign = Nothing: Set dialogFont = Nothing: Set dialogLabel = Nothing: Set dialogBorderStyle = Nothing
            Set dialogStartPosition = Nothing: Set dialogForm = Nothing: Set intPtrHWnd = Nothing: Set qtpWnd = Nothing
        End If
        
        LoadAttachment = attachment.FileName
    ElseIf attachmentList.Count = 0 Then
        Err.Raise 17, "Load Attachment", fileName & " File Not Found!"
    Else
        Err.Raise 17, "Load Attachment", "Unknown Error Loading " & fileName & "!"
    End If
    
    Set node = Nothing
    Set attachmentFilter = Nothing
    Set attachmentList = Nothing
    Set attachment = Nothing
End Function

To run a Java JAR file with the above function, you can do something like:

Code:
Dim jarPath: jarPath = LoadAttachment("Subject\Test.jar")
Dim folderPath: folderPath = Left(jarPath, InStrRev(jarPath, "\")-1)
Dim wsh: Set wsh = CreateObject("WScript.Shell")
wsh.Run "cmd /c cd " & folderPath & "&&java -jar " & jarPath, 10, True

I have not tested the second piece of code though, so you might get some errors you will have to work through. However, this should at least give you an idea of how to do what you want. Search for "WScript.Shell" and how to concat command line commands to find out what this code does.

Hope this helps!!!

P.S. Don't forget to release the objects in your final code!