07-10-2010, 12:20 PM
Hi Azeem,
We can use write function using HTML for the same.
'=============== writing to the main file =======================================================
'=============== writing to the temp file =======================================================
this is a sample script to set the result log
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
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