Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Customized HTML reports in QTP
#6
Not Solved
Hi Azeem,

We can use write function using HTML for the same.
Code:
Public Function fnSetResultLog()

    Dim objFileSystemObject, objTextFileObject
    Dim objTempFile, objFolder
    Dim sFileText
    Dim iPos

    'Creating a folder appended with date and time
      bFinalStatus=True
    tmStartTime=now
    
      Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
    
    If  not objFileSystemObject.FolderExists(gsBasicFolder)Then
        Set objFolder=objFileSystemObject.createFolder(gsBasicFolder)
    End If
    
      Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")

      If not objFileSystemObject.FileExists(gsReportFile)  Then
        'Creation of HTML file and a temp file if it does not exist already
        Set objTextFileObject= objFileSystemObject.CreateTextFile(gsReportFile, True)
        Set objTempFile= objFileSystemObject.CreateTextFile(gsTempFile, True)

        'Write initial content of file
        objTextFileObject.WriteLine "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"
        objTextFileObject.WriteLine "<HTML><BODY><CENTER>"
        objTextFileObject.WriteLine "<H1><FONT COLOR=#990000 face=""Arial"">Result Log</FONT></H1><BR>"

        objTextFileObject.WriteLine "<TABLE ALIGN=""Center"" BORDER=""1"" WIDTH=40% CELLPADDING=""1"" >"
        objTextFileObject.WriteLine "<TR BGCOLOR=""#CCCC99"">"
        objTextFileObject.WriteLine "<TD align=""left"" valign=""top""><FONT COLOR=#559999 face=""Arial""><small><B>Total Test Cases Passed: 0</B></small></FONT></TD>"
        objTextFileObject.WriteLine "</TR>"
        objTextFileObject.WriteLine "<TR BGCOLOR=""#CCCC99"">"
        objTextFileObject.WriteLine "<TD align=""left"" valign=""top""><FONT COLOR=#559999 face=""Arial""><small><B>Total Test Cases Failed: 0</B></small></FONT></TD>"
        objTextFileObject.WriteLine "</TR>"
        objTextFileObject.WriteLine "</TABLE>"
        objTextFileObject.WriteLine "<BR>"
    Else
        'Setting the position of the file if the file is already created
        Set objTextFileObject= objFileSystemObject.OpenTextFile(gsReportFile,1)
        sFileText=objTextFileObject.readall
        iPos=instr(1,sFileText,"<!--LOGDETAILS-->",vbTextCompare)
        If iPos > 0 Then
            sFileText=mid(sFileText,1,iPos-1)
            objTextFileObject.close
        End If
        
        Set objTextFileObject= objFileSystemObject.OpenTextFile(gsReportFile, 2)
        objTextFileObject.write sFileText
        
        Set objTempFile= objFileSystemObject.OpenTextFile(gsTempFile, 8)
    End If
'=============== writing to the main file =======================================================
Code:
objTextFileObject.WriteLine "<TABLE ALIGN=""Center"" BORDER=""0"" WIDTH=100% CELLPADDING=""1"" >"
    objTextFileObject.WriteLine "<TR BGCOLOR=""#aeaeff"">"            
    objTextFileObject.WriteLine "<TH width=15% rowspan=""1"" align=""left"" valign=""top""><FONT COLOR=black face=""Arial""><small><B><a href=""#" & now &  """>"  & gsTestCaseID & "</a></B></small></FONT></TH>"
    objTextFileObject.WriteLine "<TH width=85% colspan=""5"" align=""left"" valign=""center""><FONT COLOR=black face=""Arial""><small>" & gsTestCaseDesc &   "</small></FONT></TH>"
    objTextFileObject.WriteLine "</TR>"
    objTextFileObject.WriteLine "<TR BGCOLOR=""#aeaeff"">"                      
    objTextFileObject.WriteLine "<TH width=50% colspan=""2""align=""left"" valign=""center""><FONT COLOR=black face=""Arial""><small>Date: " & now & "</small></FONT></TH>"
    objTextFileObject.WriteLine "<TH width=35% colspan=""3""align=""left"" valign=""center""><FONT COLOR=black face=""Arial""><small><B>Duration:</B></small></FONT></TH>"
    objTextFileObject.WriteLine "<TH width=15% align=""left"" valign=""center""><FONT COLOR=black face=""Arial""><small><B>Status:</B></small></FONT></TH>"
    objTextFileObject.WriteLine "</TR>"
    objTextFileObject.Close

'=============== writing to the temp file =======================================================
Code:
objTempFile.WriteLine "<!--LOGDETAILS-->"
    objTempFile.WriteLine "<BR>"
    objTempFile.WriteLine "<TABLE ALIGN=""Center"" BORDER=""1"" WIDTH=100% CELLPADDING=""1"" >"
    objTempFile.WriteLine "<TR BGCOLOR=""#996600"">"            
    objTempFile.WriteLine "<TH width=15% rowspan=""1"" align=""left"" valign=""top""><FONT COLOR=white face=""Arial""><small><B><a name=""" & now & """>" & gsTestCaseID & "</a></B></small></FONT></TH>"  
    objTempFile.WriteLine "<TH width=85% colspan=""5"" align=""left"" valign=""bottom""><FONT COLOR=white face=""Arial""><small>" & gsTestCaseDesc &  "</small></FONT></TH>"
    objTempFile.WriteLine "</TR>"
    objTempFile.WriteLine "<TR BGCOLOR=""#996600"">"            '#CCCC99
    objTempFile.WriteLine "<TH width=50% colspan=""2""align=""left"" valign=""center""><FONT COLOR=white face=""Arial""><small>Date: " & now & "</small></FONT></TH>"
    objTempFile.WriteLine "<TH width=35% colspan=""3""align=""left"" valign=""center""><FONT COLOR=white face=""Arial""><small><B>Duration:</B></small></FONT></TH>"
    objTempFile.WriteLine "<TH width=15% align=""left"" valign=""center""><FONT COLOR=white face=""Arial""><small><B>Status:</B></small></FONT></TH>"
    objTempFile.WriteLine "</TR>"
    
    objTempFile.WriteLine "<TR bgColor=#996600>"
    
    objTempFile.WriteLine "<TH width=""80""colspan=""1"" ><FONT COLOR=#FF9933 face=""Arial""><small>Test Case ID</small></FONT></TH>"
    objTempFile.WriteLine "<TH width=""80""colspan=""1"" ><FONT COLOR=#FF9933 face=""Arial""><small>Request ID</small></FONT></TH>"
    
    objTempFile.WriteLine "<TH width=""80""colspan=""1"" ><FONT COLOR=#FF9933 face=""Arial""><small>Step to be Preformed</small></FONT></TH>"
    objTempFile.WriteLine "<TH width=""80""colspan=""1"" ><FONT COLOR=#FF9933 face=""Arial""><small>Status</small></FONT></TH>"
    objTempFile.WriteLine "<TH width=""80""colspan=""2"" ><FONT COLOR=#FF9933 face=""Arial""><small>Snap Shots</small></FONT></TH>"

      objTempFile.WriteLine "</TR>"    
      objTempFile.Close

    Reporter.reportEvent micDone,"Starting Test","Starting Execution of Test Case : " & gsTestCaseID

End Function
this is a sample script to set the result log
Reply


Messages In This Thread
Customized HTML reports in QTP - by azeem - 04-08-2010, 09:11 PM
RE: Customized HTML reports in QTP - by rdemers25 - 05-28-2010, 12:52 AM
RE: Customized HTML reports in QTP - by funajju - 05-28-2010, 11:47 AM
RE: Customized HTML reports in QTP - by basanth27 - 05-31-2010, 01:20 PM
RE: Customized HTML reports in QTP - by carr2805 - 07-07-2010, 04:02 AM
RE: Customized HTML reports in QTP - by Arun Prakash - 07-10-2010, 12:20 PM
RE: Customized HTML reports in QTP - by QTPScript - 08-29-2012, 09:57 PM
RE: Customized HTML reports in QTP - by vinod123 - 06-22-2013, 10:32 AM
RE: Customized HTML reports in QTP - by dfwweb - 02-26-2013, 03:22 AM
RE: Customized HTML reports in QTP - by Staff - 07-05-2013, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [UFT] Get text into DIV through HTML tag robertosalemi 2 5,533 03-29-2016, 09:43 PM
Last Post: robertosalemi
  How to attach HTML file to Email Naresh 0 3,067 04-06-2015, 02:04 PM
Last Post: Naresh
  Reports shayk1985 3 4,033 01-03-2013, 10:11 PM
Last Post: diya
  How to generate QTP report in a new file(html)? yogesh kancherla 5 14,887 10-21-2012, 04:52 PM
Last Post: yogesh kancherla
  How to open html file and update values in particular cell of a table in QTP? yogesh kancherla 2 6,082 10-11-2012, 05:59 PM
Last Post: yogesh kancherla

Forum Jump:


Users browsing this thread: 6 Guest(s)