Skip to main content

Customised HTML Result Report for UFT/QTP with ScreenShots in HP ALM TestSet attached.

On Error Resume Next
'========================================================================================================================================
'Module Name            :    GenerateCustomReport.qfl
' Author                    :    Jay
'Date Created            :     13/11/2014
'Description                :     The library contains various functions that are used to generate a Custom HTML report
'========================================================================================================================================
'Project/Test Specific Variables
Public blnGlobalHTMLReport : blnGlobalHTMLReport = True     ' is a global variable. If this is set to true then Custom HTML Reporting will be enabled for the Test
Public blnGlobalQTPReport : blnGlobalQTPReport = True         ' is a global variable. If this is set to FALSE then the Reporter events will NOT be logged by this function only. Reporter events called outside this function will be logged
Environment.Value("strProjectName") = "Sample_ProjectName"                              ' The Project name
Environment.Value("ResultPath")  = "C:\Temp"                                  'The local system path whether the HTML reports should be saved

'Global Variables used for HTML Reporting. These variables are using by the functions internally to track the number of verification points and whether the scripts is execute form QC
Public blnIsExecFromQC : blnIsExecFromQC = False
Public intPassCounter : intPassCounter= 0
Public intFailCounter : intFailCounter= 0
Public intVerificationNo : intVerificationNo= 0
Public intWarningCounter : intWarningCounter = 0

'========================================================================================================================================
'Function Name                            :    Initialize_HTML_Report
' Author                        :    Jay
'Description                    :    Function to create QTP Custom Reporting in HTML format
'Notes                        :    This step should be called at the start of the test
'Input Parameter                         :    None
'Return Value                                :    None
'Date Created                                :    13/11/2014
'========================================================================================================================================
Function Initialize_HTML_Report()  
    Dim strTimeStampDate, strTimeStampTime
    Dim objFSO, ResFile
    Dim strResPath, strTempTestName
    Dim objCurTestSet
    Dim arrFolders, strTempFold, i
    Dim strHeadColor : strHeadColor="#12579D"

    If blnGlobalHTMLReport Then
        'Identify whether the Script is executed for QC or Not
        If QCUtil.IsConnected Then
            Set objCurTestSet = QCUtil.CurrentTestSetTest
            If objCurTestSet is Nothing Then
                blnIsExecFromQC = False
            Else
                blnIsExecFromQC = True
            End If
        Else
            blnIsExecFromQC = False
        End If
   
        strTimeStampDate = Month(Now) & "-" & Day(Now) & "-" & Year(Now)
        strTimeStampTime =  Hour(Now) & "_" & Minute(Now)
   
        'Create the Results Path based on Current Time  
        strResPath = Environment.Value("ResultPath") & "\" & "HTML Results\" & strTimeStampDate & "\" & Environment.Value("TestName") &"_" & strTimeStampTime
        Environment.Value("strResPath") = strResPath
        Environment.Value("strScreenShotPath") = strResPath & "\ScreenShots"

        'Create the Results File Name based on Current Time        
        strTempTestName =  "TestResult" &"_" & strTimeStampTime & ".html"                                   
        Environment.Value("strResFile") = strResPath & "\" & strTempTestName
                   
        'Create the Folder If required
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        If Not objFSO.FolderExists(Environment.Value("strScreenShotPath") ) Then
            arrFolders = Split(Environment.Value("strScreenShotPath") ,"\")
            strTempFold = arrFolders(0)
            For i = 1 to UBound(arrFolders)
                strTempFold = strTempFold & "\" & arrFolders(i)
                If Not objFSO.FolderExists(strTempFold) Then
                    objFSO.CreateFolder(strTempFold)
                End If
            Next
        End If
                   
        'Create a HTML Report file
        Set ResFile = objFSO.CreateTextFile(Environment.Value("strResFile")True)
        ResFile.Close
        Reporter.ReportEvent micInfo,"ReportFile Created","Path: " & Environment.Value("strResFile")
       
        'Open the HTML file for writing
        If Not objFso.FileExists(Environment.Value("strResFile"))Then
            Reporter.ReportEvent micFail,"Open Report FIle","File Not Found." & Vblf & Environment.Value("strResFile")           
            Exit Function
        End If
        Set ResFile = objFSO.OpenTextFile(Environment.Value("strResFile"),8)
   
        'Create the Report header
        ResFile.Writeline("")
        ResFile.Writeline("")
        ResFile.Writeline("& "Content-Language" & "content=" & "en-us>")
        ResFile.Writeline("& "Content-Type" & "content=" & "text/html; charset=windows-1252" & ">")
        ResFile.Writeline(" Test Case Automation Execution Results")
        ResFile.Writeline("")                    
        ResFile.Writeline("")       
        ResFile.Writeline("")
        ResFile.Writeline("
"
)                                          
        ResFile.Writeline("
&
 "#000000 id=table1 width=900 height=31 cellspacing=0 bordercolorlight=" & "#FFFFFF>")       
        ResFile.Writeline(" " )
        ResFile.Writeline("& strHeadColor & ">")
        ResFile.Writeline("
&
 chr(34)&"Copperplate Gothic Bold"&chr(34) & "> " & Environment.Value("TestName")  & " - Automation Execution Results" & "& chr(34)&"Copperplate Gothic Bold"&chr(34) & "> ")
        ResFile.Writeline("")
        ResFile.Writeline("")       
        ResFile.Writeline(" " )
        ResFile.Writeline("& strHeadColor & ">")
        ResFile.Writeline("
"
& " "& "PROJECT: " &   Environment.Value("strProjectName"))
        ResFile.Writeline("")       
        ResFile.Writeline("& strHeadColor & ">")
        ResFile.Writeline("
"
& " "& "DATE: " &  strTimeStampDate & " " & Time )       
        ResFile.Writeline("")
        ResFile.Writeline("")
       
        'If the script is executed from QC report the Test Set Name and Test CurrentRun
        If blnIsExecFromQC Then
            ResFile.Writeline(" " )
            ResFile.Writeline("& strHeadColor & ">")
            ResFile.Writeline("
"
& " "& "QC TEST SET NAME: " &  QCUtil.CurrentTestSet.Name)
            ResFile.Writeline("")           
            ResFile.Writeline("& strHeadColor & ">")
            ResFile.Writeline("
"
& " "& "QC TEST RUN NAME: " &  QCUtil.CurrentRun.Name)
            ResFile.Writeline("")
            ResFile.Writeline("")
        End If

        ResFile.Writeline("&
 "#000000 id=table1 width=900 height=31 cellspacing=0 bordercolorlight=" & "#FFFFFF>")                                                          
        ResFile.Writeline(""
)                                                                   
        ResFile.Writeline("
&
 "#000000 id=table1 width=900 height=31 cellspacing=0 bordercolorlight=" & "#FFFFFF>")
        ResFile.Writeline(" &  strHeadColor & ">")
        ResFile.Writeline("& "400")
        ResFile.Writeline("
&
 "center>& "Arial Narrow " & "size=" & "2" & ">" & "Iteration")
        ResFile.Writeline("")       
        ResFile.Writeline("& "400")
        ResFile.Writeline("
&
 "center>& "Arial Narrow " & "size=" & "2" & ">" & "Action Name")
        ResFile.Writeline("")       
        ResFile.Writeline("& "1600")
        ResFile.Writeline("
&
 "center>& "Arial Narrow " & "size=" & "2" & ">" & "Step Name")
        ResFile.Writeline("")       
        ResFile.Writeline("& "1600")
        ResFile.Writeline("
&
 "center>& "Arial Narrow " & "size=" & "2" & ">" & "Description")
        ResFile.Writeline("")       
        ResFile.Writeline("& "400")
        ResFile.Writeline("
&
 "center>& "Arial Narrow " & "size=" & "2" & ">" & "Status")
        ResFile.Writeline("")       
        ResFile.Writeline("& "400")
        ResFile.Writeline("
&
 "center>& "Arial Narrow " & "size=" & "2" & ">" & "Time")
        ResFile.Writeline("")       
        ResFile.Writeline("& "400")
        ResFile.Writeline("
&
 "center>& "Arial Narrow " & "size=" & "2" & ">" & "Screenshot")
        ResFile.Writeline("")
        ResFile.Writeline("")
   
        'Close the results File
        ResFile.Close       
        Set ResFile = Nothing
        Set objFSO = Nothing
    End If
End Function

'=========================================================================================================================================================================================================================
'Function Name                    :     Custom_Report_Step
'Description                        :     To Add Report Steps to the Custom HTML Report
'Author                            :    Jay
'Notes                            :    The "Initialize_HTML_Report" function should be called before calling this function 
'Input Parameter                                  :     strStepName - The Step Name to be reported
'                                    strStepDetail - The Step Details to be reported
'                                    strStepStatus - The execution  status for the respective step
'    
'                                    varReportParams - This parameter contains the following 5 parameter separated by "|"
'                                        1) blnQTPReport - Setting the Value to true will enable the Standard reporter event for the respective step ONLY
'                                        2) blnHTMLReport -  Setting the Value to true will enable the Custom HTML reporter event for the respective step ONLY
'                                        3) blnCaptureBitMap - If TRUE the desktop screenshot is captured. For all FAILED steps the screen shot will be captured irrespective of the parameter value
'                                        4)blnExitTest - If TRUE, The script execution will be stopped
'                                        5)blnExitAction - If TRUE, The action execution will be stopped and script will continue to run
'    
'                                    If the Parameter is Invalid or empty its value will be set to DEFAULT
'    
'                                    Default value would be "T|T|F|F|F" for a step with "PASS" ,"DONE" status and "T|T|T|F|F" for a step with status of "FAIL" or "WARNING"
'    
'                                    For this parameter we use the following strings
'                                        1) "DEFAULT” - would set the parameter to Default based on the step Status. It would report the step in both QTP standard report and the Custom HTML report.
'                                        2) “DEFAULT_QTP” - would set the parameter to Default based on the step Status and it will report the step in the QTP standard report only. It will not report the step in Custom HTML report.
'                                        3) "DEFAULT_EXIT" - would set the parameter to Default based on the step Status and it will set blnExitTest(4th parameter of varReportParams) to "TRUE"
'                                        4) DEFAULT_EXIT_ACTION  - would set the parameter to Default based on the step Status and it will set blnTempExitAction(5th parameter of varReportParams) to "TRUE"

'
'                                    varOptional - Parameter for future use.
'Return Value                                       :    None
'Date Created                                       :     13/11/2014
'=========================================================================================================================================================================================================================
Function Custom_Report_Step(strStepName, strStepDetail, strStepStatus, varReportParams, objCaptureObject, varOptional)
    Dim objFSO, ResFile
    Dim arrTemp_Rep
    Dim blnTempQTP : blnTempQTP = False
    Dim blnTempHTML : blnTempHTML = False
    Dim blnTempCapture : blnTempCapture = False
    Dim blnTempExit : blnTempExit = False
    Dim strEvent
    Dim strScreenShotName
    Dim dtstamp
    Dim objRegEx, blnRetVal
    Dim objQTPApp

    'Set the default value of the varReportParams if Empty or if it is Invalid
    Select Case UCase(varReportParams)
   
        Case "DEFAULT"
            If Ucase(strStepStatus) = "FAIL" Or  Ucase(strStepStatus) = "WARNING" Then               
                varReportParams = "T|T|T|F|F"
            Else               
                varReportParams = "T|T|F|F|F"
            End If

        Case "DEFAULT_QTP"
            If Ucase(strStepStatus) = "FAIL" Or  Ucase(strStepStatus) = "WARNING" Then
                varReportParams = "T|F|T|F|F"
            Else
                varReportParams = "T|F|F|F|F"
            End If

        Case "DEFAULT_EXIT"
            If Ucase(strStepStatus) = "FAIL" Or  Ucase(strStepStatus) = "WARNING" Then               
                varReportParams = "T|T|T|T|F"
            Else               
                varReportParams = "T|T|F|T|F"
            End If

        Case "DEFAULT_EXIT_ACTION"
            If Ucase(strStepStatus) = "FAIL" Or  Ucase(strStepStatus) = "WARNING" Then               
                varReportParams = "T|T|T|F|T"
            Else               
                varReportParams = "T|T|F|F|T"
            End If
    End Select
   
    If Len(Trim(varReportParams)) <> 9 Then
            If Ucase(strStepStatus) = "FAIL" Or  Ucase(strStepStatus) = "WARNING" Then               
                varReportParams = "T|T|T|F|F"
            Else               
                varReportParams = "T|T|F|F|F"
            End If
    Else
        Set objRegEx = New RegExp   ' Create a regular expression.
        objRegEx.Pattern = "(T|F)\|(T|F)\|(T|F)\|(T|F)|(T|F)"
        blnRetVal = objRegEx.Test(Ucase(varReportParams))

        'If Invalid set it to Default
        If Not(blnRetVal) Then
            If Ucase(strStepStatus) = "FAIL" Or  Ucase(strStepStatus) = "WARNING" Then       
                varReportParams = "T|T|T|F|F"
            Else               
                varReportParams = "T|T|F|F|F"
            End If
        End If
    End If
   
    'Split the varReportParams parameters
    arrTemp_Rep = Split(varReportParams, "|")

    'QTP Rep
    If Ucase(arrTemp_Rep(0)) = "T" Then blnTempQTP = True

    'Html Rep
    If Ucase(arrTemp_Rep(1)) = "T" Then blnTempHTML = True

    'Capture Image
    If Ucase(arrTemp_Rep(2)) = "T" Then blnTempCapture = True

    'Exit Temp
    If Ucase(arrTemp_Rep(3)) = "T" Then blnTempExit = True

    'Exit Action    
    If Ucase(arrTemp_Rep(4)) = "T" Then blnTempExitAction = True

    'If QTP reporting is enabled
    If blnTempQTP And blnGlobalQTPReport Then
        Select Case UCase(strStepStatus)
            Case "PASS"
                strEvent = micPass
            Case "FAIL"
                strEvent = micFail
            Case "WARNING"
                strEvent = micWarning
            Case "INFORMATION"
                strEvent = micInfo
            Case Else
                strEvent = micDone
        End Select

        'Report the Details
        If blnTempExit Then
            Reporter.ReportEvent  strEvent, strStepName, strStepDetail & vbnewline & "Exiting the test on User Request"
        Else
            Reporter.ReportEvent  strEvent, strStepName, strStepDetail
        End If
    End If

    'If Custom HTML reporting is enabled 
    If blnTempHTML And blnGlobalHTMLReport Then
   
        'Open the HTML file for writing    
        strResFilePath = Environment.Value("strResFile")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        If ObjFSO.FileExists(strResFilePath) Then
            Set ResFile = objFSO.OpenTextFile(Environment.Value("strResFile"),8)       
            ResFile.Writeline(" " )
            ResFile.Writeline("& "400>")
            ResFile.Writeline("
&
 "center>& "Verdana " & "size=" & "2" & ">"  &   Environment.Value("TestIteration"))
            ResFile.Writeline("")
            ResFile.Writeline("& "400>")
            ResFile.Writeline("
&
 "center>& "Verdana " & "size=" & "2" & ">"  &   Environment.Value("ActionName"))
            ResFile.Writeline("")
            ResFile.Writeline("& "400>")
            ResFile.Writeline("
&
 "center>& "Verdana " & "size=" & "2" & ">"  &  strStepName)
            ResFile.Writeline("")
            ResFile.Writeline("& "400>")
            If blnTempExit Then
                ResFile.Writeline("
&
 "center>& "Verdana " & "size=" & "2" & ">"  &  strStepDetail & ".
Exiting the test on User Request"
)
            Else
                ResFile.Writeline("
&
 "center>& "Verdana " & "size=" & "2" & ">"  &  strStepDetail)
            End If
            ResFile.Writeline("")
            ResFile.Writeline("& "400>")
            If Trim(strStepStatus) = "" Then
                strStepStatus = "-"
            Else
                strStepStatus = UCase(strStepStatus)
            End If
   
            If UCase(strStepStatus)="PASS" Then
                ResFile.Writeline("
&
 "center" & ">" & "& "Verdana " & "size=" & "2" & " color=" & "#008000" & ">" & strStepStatus & "")
                intPassCounter=intPassCounter+1         
                intVerificationNo=intVerificationNo+1
            ElseIf UCase(strStepStatus)="FAIL" Then
                ResFile.Writeline("
&
 "center" & ">" & "& "Verdana " & "size=" & "2" & " color=" & "#FF0000" & ">" & strStepStatus & "")
                intFailCounter=intFailCounter+1
                intVerificationNo=intVerificationNo+1
            ElseIf UCase(strStepStatus)="WARNING" Then
                ResFile.Writeline("
&
 "center" & ">" & "& "Verdana " & "size=" & "2" & " color=" & "#FF8C00" & ">" & strStepStatus & "")
                intWarningCounter=intWarningCounter+1
                intVerificationNo=intVerificationNo+1
            Else
                ResFile.Writeline("
&
 "center" & ">" & "& "Verdana " & "size=" & "2" & " color=" & "#8A4117" & ">" & strStepStatus & "")                      
            End If
            ResFile.Writeline("")       
            ResFile.Writeline("& "400>")
            ResFile.Writeline("
&
 "center>& "Verdana " & "size=" & "2" & ">"  &  Time)
            ResFile.Writeline("")
   
            'Capture Screen shot
            If blnTempCapture Then
                'Minimize QTP
                Set objQTPApp = Getobject("","QuickTest.Application")               
                objQTPApp.WindowState = "Minimized"
                Set objQTPApp = Nothing
   
                'Create the File Name
                dtstamp = "_" &Month(now) & "_" & Day(now) & "_" & Hour(now) & "_" & Minute(now) & "_" & Second(now)
                strScreenShotName = "ErrorScreenShot" & dtstamp
                If IsObject(objCaptureObject) Then
                    If Not(objCaptureObject is Nothing) Then
                        objCaptureObject.CaptureBitmap Environment.Value("strScreenShotPath") &"\" & strScreenShotName & ".png"True
                    Else
                        Desktop.CaptureBitmap Environment.Value("strScreenShotPath") &"\" & strScreenShotName & ".png"True
                    End If
                Else
                    Desktop.CaptureBitmap Environment.Value("strScreenShotPath") &"\" & strScreenShotName & ".png"True
                End If
            Else
                strScreenShotName = "-"
            End If
       
            ResFile.Writeline("& "400>")
            ResFile.Writeline("
&
 "center>& "Verdana " & "size=" & "2" & ">"  &  strScreenShotName)
            ResFile.Writeline("")
            ResFile.Writeline("")
           
            'Close the Results File
            ResFile.Close
       
        Else
            Reporter.ReportEvent micDone,"Verify Result FIle Path","FIle does not exist. " & VBlf & strResFilePath
        End If
        Set objFSO = Nothing
        Set ResFile = Nothing
    End If
   
    'If blnTempExit is True. Upload report to QC and Exit the Test
    If blnTempExit Then               
        Call Custom_Report_Wrapup()
        'Exit the Test        
        ExitTest()
    End If

    'Added the appropriate conditional for the ExitAction statement
    If blnTempExitAction Then ExitAction()
    Custom_Report_Step = 0
End Function

'==========================================================================================================================
'Function Name                            :    Custom_Report_Wrapup
'Description                    :     To add footer to  the Custom Report and Upload the report to QC if the test is executed from QC. 
'Notes                        :    This step should be called before exiting the test
'Input Parameter                :    None
'Return Value                :    None
'Date Created                                :    13/11/2014                                 
'==========================================================================================================================
Function Custom_Report_Wrapup()
    Dim objFSO, ResFile

    If blnGlobalHTMLReport Then
        'Open the HTML file for writing    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set ResFile = objFSO.OpenTextFile(Environment.Value("strResFile"),8)
   
        ResFile.Writeline("")                   
        ResFile.Writeline("&
 "#000000 id=table1 width=900 height=31 cellspacing=0 bordercolorlight=" & "#FFFFFF>")                                          
        ResFile.Writeline(" " )
        ResFile.Writeline("")
        ResFile.Writeline("
"
& " "& "No. Of Verification Points :  " &  intVerificationNo & " ")
        ResFile.Writeline("")       
        ResFile.Writeline("")       
        ResFile.Writeline("
"
& " "& "Passed :  " &  intPassCounter & " ")
        ResFile.Writeline("")       
        ResFile.Writeline("")       
        ResFile.Writeline("
"
& " "& "Failed :  " &  intFailCounter & " ")
        ResFile.Writeline("")       
        ResFile.Writeline("")       
        ResFile.Writeline("
"
& " "& "Warnings :  " &  intWarningCounter & " ")
        ResFile.Writeline("")       
        ResFile.Writeline("")            
        ResFile.Writeline("")                                                     
        ResFile.Writeline("")       
        ResFile.Writeline("")
        ResFile.Writeline("")
        ResFile.Close
   
        'If Executed From QC Upload the HTML report
        If blnIsExecFromQC Then
            Call QC_AttachFileToTestRun(Environment.Value("strResFile"))
            Call QC_AttachScreenshots(Environment.Value("strScreenShotPath"))
        End If
   
        Set objFSO = Nothing
        Set ResFile = Nothing
    End If
End Function

'=====================================================================================================================
'Function Name                            :    QC_AttachFileToTestRun
'Description                    :     To Upload the required File to QC 
'Author                        :    Jay
'Input Parameter                         :     strFilePath - The complete path with the file name
'Return Value                                :     None
'Date Created                                :    13/11/2014                                 
'=====================================================================================================================
Function QC_AttachFileToTestRun(strFilePath)
    Dim objQCAttachments, objQCAttachments_Item
    Set objQCAttachments =  QCUtil.CurrentRun.Attachments
    Set objQCAttachments_Item = objQCAttachments.AddItem(Null)
    objQCAttachments_Item.FileName = strFilePath
    objQCAttachments_Item.Type = 1
    objQCAttachments_Item.Post
    Set objQCAttachments = Nothing
    Set objQCAttachments_Item = Nothing
End Function

'=====================================================================================================================
'Function Name                              :    QC_AttachScreenshots
'Description                                 :    To attach the screenshots to test run in QC
'Author                          :    Jay
'Input Parameter                           :     strScreenshotsFolder - The complete path of the folder that has the screenshots
'Return Value                                  :     None
'Date Created                                  :     13/11/2014                                 
'=====================================================================================================================
Function QC_AttachScreenshots (strScreenshotsFolder)
    Dim objFSO,  objFolderName, objfileList, objFile

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolderName = objFSO.GetFolder(strScreenshotsFolder)
    Set objfileList = objFolderName.Files
    For each objFile in objfileList
        Call QC_AttachFileToTestRun(objFile.Path)
    Next
       'objFSO.DeleteFolder(Environment.Value("strResPath"))
    Set objFSO = Nothing
    Set objFolderName = Nothing
    Set objfileList = Nothing
End Function
'======================================== E N D ==============================================================================

Comments

Popular posts from this blog

Convert JSON to XML using QTP/UFT/VBScript

Sample Code : Dim strPage,strJSON,objIE strPage = "C:\Jay\JLoader.html" Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate2 strPage While objIE.Busy : Wend strJSON = "{""FirstName"":""Jay"", ""LastName"":""Krishna""}" Set objWin = objIE.document.parentWindow objWin.execScript "var jsonStr2XML = function(strJSON) { return json2xml(JSON.parse(strJSON));};" Msgbox  oWin.jsonStr2XML(strJSON) objIE.Quit In Detail: Converting The most popular data interchange format JSON(JavaScript Object Notation) to XML using QTP/UFT. Parsing JSON in UFT could be a challenge so we will use JavaScript in UFT to make it perfect. SO We need :              Java Script API  - To Convert JSON to XML                         JavaScript Files :                         http://goessner.net/download/prj/jsonxml/j

Read Outlook mail attachment and Body using Vb Script or QTP

Set olApp = CreateObject("Outlook.Application") Set olns = olApp.GetNameSpace("MAPI") Set ObjFolder = olns.GetDefaultFolder(6) j = 0 For each item1 in ObjFolder.Items        iattachCnt = item1.Attachments.Count     Print "Attachments Count: " & iattachCnt     For i = 1 to iattachCnt         Print "FileName :    " & item1.Attachments(i).FileName         Print "Display Name:   " & item1.Attachments(i).DisplayName         Print "Size: " & item1.Attachments(i).Size     Next     Print " Body : " & item1.body     Print "--------------------------------------Mail Num - " & j & " -----------------------------------------------"     j = j+1    Next

Excel Sorting By Rows and Columns

Excel Sorting By Row: Const xlAscending = 1 Const xlNo = 2 Const xlSortRows = 2 Set objExcel = CreateObject(“Excel.Application”) objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”) Set objWorksheet = objWorkbook.Worksheets(1) objWorksheet.Cells(1,1).activate Set objRange = objExcel.ActiveCell.EntireRow objRange.Sort objRange, xlAscending, , , , , , xlNo, , , xlSortRows set objExcel=nothing Excel Sorting By Column : Const xlAscending = 1′represents the sorting type 1 for Ascending 2 for Desc Const xlYes = 1 Set objExcel = CreateObject(“Excel.Application”)’Create the excel object objExcel.Visible = True’Make excel visible Set objWorkbook = _ objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”)’Open the document Set objWorksheet = objWorkbook.Worksheets(1)’select the sheet based on the index .. 1,2 ,3 … Set objRange = objWorksheet.UsedRange’which select the range of the cells has some data other than blank Set objRange2 = objExcel.Range

How to Read or Select Context Menu or Right Click Menu using QTP.

Select The Item in Right Click Menu or Context Menu: Window("sampleWindow").WinMenu("MenuObjType:=1).Select"File;New" Here MenuObjtype can be 1 r 2 r 3 .......n Check wether the Item is Exist or Not: If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("1","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If                                         Or If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("File","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If Get the Items in Context Menu: For i = 1 to 10 Print  Window("sampleWindow").WinMenu("MenuObjType:=" & i).GetItemProperty("1","Label") Then Next

How to Download a file using VbScript

Following is the code to download a file using Vbscript, without using QTP This code uses the HTMLDom and URLDownloadToFile method from urlmon API. Since VBScript does support calling Native API methods directly, here I am using  Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file Private Declare Function URLDownloadToFile Lib “urlmon” Alias _                                            “URLDownloadToFileA” ( _                                            ByVal pCaller As Long, ByVal szURL As String, _                                            ByVal szFileName As String, _                                            ByVal dwReserved As Long, _                                            ByVal lpfnCB As Long) As Long Sub FileSave(strUrl, Des)     r = URLDownloadToFile(0, strUrl, Des, 0, a)