Customized HTML reports in UFT
Public strHTMLFileName,strFileURL,htmlresult,fso
@@@@@@@@@@@@@@@@@
Function OpenFile()
On error resume next
strHTMLFileName= gbReportFilePath & "\TestResult_" & Day(now) & "_" & month(now) & "_" & year(now) & "_" & hour(now) & "_" & minute(now) &".html"
StartTime = Timer
stTime = Time
Set fso = CreateObject("Scripting.FileSystemObject")
Set htmlresult = fso.CreateTextFile(strHTMLFileName, ForWriting, True)
'OpenTextFile(strHTMLFileName, ForWriting, True)
strFileURL = strHTMLFileName
CreateHeader
End Function
@@@@@@@@@@@@
'Create header in reporter file
Function CreateHeader()
On error resume next
htmlresult.writeline("<html>")
htmlresult.writeline("<title>"&Environment("TestName")&"</title>")
htmlresult.WriteLine("<head></head>")
htmlresult.WriteLine("<body>")
htmlresult.WriteLine("<font face='Tahoma'size='2'>")
htmlresult.WriteLine("<h1> Automation Test Results</h1>")
htmlresult.writeline("<table border='0' width='100%' height='47'>")
htmlresult.writeline("<tr>")
'htmlresult.writeline("<td width='13%' bgcolor='#5555FE' align='center'><b><font color='#000000' face='Tahoma' size='2'>TestCaseID</font></b></td>")
htmlresult.writeline("<td width='24%' bgcolor='#5555FE'><b><font color='#000000' face='Tahoma' size='2'>Testcase Description</font></b></td>")
'htmlresult.writeline("<td width='23%' bgcolor='#5555FE'><b><font color='#000000' face='Tahoma' size='2'>Expected Result</font></b></td>")
htmlresult.writeline("<td width='22%' bgcolor='#5555FE'><b><font color='#000000' face='Tahoma' size='2'> Result </font></b></td>")
htmlresult.writeline("<td width='18%' bgcolor='#5555FE' align='center'><b><font color='#000000' face='Tahoma' size='2'>Pass/Fail</font></b></td>")
htmlresult.writeline("<td width='18%' bgcolor='#5555FE' align='center'><b><font color='#000000' face='Tahoma' size='2'>Screenshot</font></b></td>")
htmlresult.writeline("</tr>")
End Function
@@@@@@@@@@@@@@
'Call in test results
Function TestResult(strObjective, strActualResult,strPassFail,Strfilename)
On error resume next
'strScreenshot="K:\everyone\QA_Coimbatore\error.png"
htmlresult.writeline("<tr>")
'htmlresult.writeline("<td width='13%' bgcolor='#FFFFDC' valign='middle' align='center'>" & strTCID & "</td>")
htmlresult.writeline("<td width='24%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strObjective & "</td>")
'htmlresult.writeline("<td width='23%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strExpectedResult & "</td>")
htmlresult.writeline("<td width='22%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strActualResult & "</td>")
'screenshot = "c:\error.jpeg"
if lcase(strPassFail) = "pass" then
'CaptureScreenshot
htmlresult.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='Green' face='Tahoma' size='2'>" & strPassFail & "</font></b></td>")
intPass = intPass + 1
ElseIf lcase(strPassFail) = "fail" Then
'CaptureScreenshot
'htmlresult.writeline("<td width='22%' bgcolor='#FFFFDC' valign='top' align='justify'></td>")
htmlresult.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='Red' face='Tahoma' size='2'>" & strPassFail & "</font></b></td>")
htmlresult.writeline("<td><base target="& "_blank "& "><a href="& ErrorSnap & " target=" & "_blank" & "data-title= Image" & "> Error Message </a></td>")
intFail = intFail + 1
else
htmlresult.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='Orange' face='Tahoma' size='2'> Not applicable </font></b></td>")
intPass = intPass + 1
end if
htmlresult.writeline("</tr>")
End Function
@@@@@@@@@@@@@@@@
Create footer total test case Pass or Fail and time
Function Footer()
On error resume next
Dim EndTime
EndTime = Timer
enTime = Time
htmlresult.writeline("</table>")
htmlresult.writeline("<hr>")
htmlresult.writeline("<table border='0' width='50%'>")
htmlresult.writeline("<tr><td width='100%' colspan='2' bgcolor='#5555FE'><b><font face='Tahoma' size='2' color='#FFFFFF'>Summary</font></b></td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#029C0F'><b><font face='Tahoma' size='2'>Total Tesresult Passed</font></b></td><td width='55%' bgcolor='#029C0F'>" & intPass & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FB0505'><b><font face='Tahoma' size='2'>Total Tesresult Failed</font></b></td><td width='55%' bgcolor='#FB0505'>" & intFail & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Execution Url</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & gburl & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Executed On</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & Date & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Start Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & stTime & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>End Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & enTime & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Execution Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & int((CDbl(EndTime - StartTime))/60) & " Minutes"& "</td></tr>")
htmlresult.writeline("</table>")
htmlresult.writeline("</font>")
htmlresult.WriteLine("</body>")
htmlresult.WriteLine("</html>")
End Function
@@@@@@@@@@@
Open the HTML Report
Function CloseFile()
On error resume next
Footer()
htmlresult.close()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.visible = True
objIE.Navigate strFileURL
End Function
@@@@@@@@@@@@@@@@@
Function OpenFile()
On error resume next
strHTMLFileName= gbReportFilePath & "\TestResult_" & Day(now) & "_" & month(now) & "_" & year(now) & "_" & hour(now) & "_" & minute(now) &".html"
StartTime = Timer
stTime = Time
Set fso = CreateObject("Scripting.FileSystemObject")
Set htmlresult = fso.CreateTextFile(strHTMLFileName, ForWriting, True)
'OpenTextFile(strHTMLFileName, ForWriting, True)
strFileURL = strHTMLFileName
CreateHeader
End Function
@@@@@@@@@@@@
'Create header in reporter file
Function CreateHeader()
On error resume next
htmlresult.writeline("<html>")
htmlresult.writeline("<title>"&Environment("TestName")&"</title>")
htmlresult.WriteLine("<head></head>")
htmlresult.WriteLine("<body>")
htmlresult.WriteLine("<font face='Tahoma'size='2'>")
htmlresult.WriteLine("<h1> Automation Test Results</h1>")
htmlresult.writeline("<table border='0' width='100%' height='47'>")
htmlresult.writeline("<tr>")
'htmlresult.writeline("<td width='13%' bgcolor='#5555FE' align='center'><b><font color='#000000' face='Tahoma' size='2'>TestCaseID</font></b></td>")
htmlresult.writeline("<td width='24%' bgcolor='#5555FE'><b><font color='#000000' face='Tahoma' size='2'>Testcase Description</font></b></td>")
'htmlresult.writeline("<td width='23%' bgcolor='#5555FE'><b><font color='#000000' face='Tahoma' size='2'>Expected Result</font></b></td>")
htmlresult.writeline("<td width='22%' bgcolor='#5555FE'><b><font color='#000000' face='Tahoma' size='2'> Result </font></b></td>")
htmlresult.writeline("<td width='18%' bgcolor='#5555FE' align='center'><b><font color='#000000' face='Tahoma' size='2'>Pass/Fail</font></b></td>")
htmlresult.writeline("<td width='18%' bgcolor='#5555FE' align='center'><b><font color='#000000' face='Tahoma' size='2'>Screenshot</font></b></td>")
htmlresult.writeline("</tr>")
End Function
@@@@@@@@@@@@@@
'Call in test results
Function TestResult(strObjective, strActualResult,strPassFail,Strfilename)
On error resume next
'strScreenshot="K:\everyone\QA_Coimbatore\error.png"
htmlresult.writeline("<tr>")
'htmlresult.writeline("<td width='13%' bgcolor='#FFFFDC' valign='middle' align='center'>" & strTCID & "</td>")
htmlresult.writeline("<td width='24%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strObjective & "</td>")
'htmlresult.writeline("<td width='23%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strExpectedResult & "</td>")
htmlresult.writeline("<td width='22%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strActualResult & "</td>")
'screenshot = "c:\error.jpeg"
if lcase(strPassFail) = "pass" then
'CaptureScreenshot
htmlresult.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='Green' face='Tahoma' size='2'>" & strPassFail & "</font></b></td>")
intPass = intPass + 1
ElseIf lcase(strPassFail) = "fail" Then
'CaptureScreenshot
'htmlresult.writeline("<td width='22%' bgcolor='#FFFFDC' valign='top' align='justify'></td>")
htmlresult.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='Red' face='Tahoma' size='2'>" & strPassFail & "</font></b></td>")
htmlresult.writeline("<td><base target="& "_blank "& "><a href="& ErrorSnap & " target=" & "_blank" & "data-title= Image" & "> Error Message </a></td>")
intFail = intFail + 1
else
htmlresult.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='Orange' face='Tahoma' size='2'> Not applicable </font></b></td>")
intPass = intPass + 1
end if
htmlresult.writeline("</tr>")
End Function
@@@@@@@@@@@@@@@@
Create footer total test case Pass or Fail and time
Function Footer()
On error resume next
Dim EndTime
EndTime = Timer
enTime = Time
htmlresult.writeline("</table>")
htmlresult.writeline("<hr>")
htmlresult.writeline("<table border='0' width='50%'>")
htmlresult.writeline("<tr><td width='100%' colspan='2' bgcolor='#5555FE'><b><font face='Tahoma' size='2' color='#FFFFFF'>Summary</font></b></td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#029C0F'><b><font face='Tahoma' size='2'>Total Tesresult Passed</font></b></td><td width='55%' bgcolor='#029C0F'>" & intPass & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FB0505'><b><font face='Tahoma' size='2'>Total Tesresult Failed</font></b></td><td width='55%' bgcolor='#FB0505'>" & intFail & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Execution Url</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & gburl & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Executed On</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & Date & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Start Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & stTime & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>End Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & enTime & "</td></tr>")
htmlresult.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Execution Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & int((CDbl(EndTime - StartTime))/60) & " Minutes"& "</td></tr>")
htmlresult.writeline("</table>")
htmlresult.writeline("</font>")
htmlresult.WriteLine("</body>")
htmlresult.WriteLine("</html>")
End Function
@@@@@@@@@@@
Open the HTML Report
Function CloseFile()
On error resume next
Footer()
htmlresult.close()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.visible = True
objIE.Navigate strFileURL
End Function
Comments
Post a Comment