HTML report 类
上一篇 / 下一篇 2009-08-25 15:05:12 / 个人分类:watir+ruby
将下面的代码保存为CLReport.class.rb作为公共库
class CLReport
# Initialize the report class
def initialize()
@overallResult = 'PASSED'
@reportContent1 = ''
@reportContent2 = ''
end
# Create a report
def createReport(reportName)
# Get current time
t = Time.now
# Format the day
if(t.day.to_s.length == 1)
strDay = '0' + t.day.to_s
else
strDay = t.day.to_s
end
# Format the month
if(t.month.to_s.length == 1)
strMonth = '0' + t.month.to_s
else
strMonth = t.month.to_s
end
# Format the year
strYear = t.year.to_s
# Format the hour
if(t.hour.to_s.length == 1)
strHour = '0' + t.hour.to_s
else
strHour = t.hour.to_s
end
# Format the minutes
if(t.min.to_s.length == 1)
strMinutes = '0' + t.min.to_s
else
strMinutes = t.min.to_s
end
# Format the seconds
if(t.sec.to_s.length == 1)
strSeconds = '0' + t.sec.to_s
elsif (t.sec.to_s.length == 0)
strSeconds = '00'
else
strSeconds = t.sec.to_s
end
# Create the report name
strTime = '_' + strDay + strMonth + strYear + '_' + strHour + strMinutes + strSeconds + '.html'
strNiceTime = strDay + '-' + strMonth + '-' + strYear + ' @ ' + strHour + ':' + strMinutes + ':' + strSeconds
strTotalReport = reportName + strTime
# Create the HTML report
strFile = File.open(strTotalReport, 'w')
# Format the header of the HTML report
@reportContent1 = '<html>
<head>
<meta. content=text/html; charset=ISO-8859-1 http-equiv=content-type>
<title>QA Test Report</title>
<style. type=text/css>
.title { font-family: verdana; font-size: 30px; font-weight: bold; align: left; color: #045AFD;}
.bold_text { font-family: verdana; font-size: 12px; font-weight: bold;}
.normal_text { font-family: verdana; font-size: 12px; font-weight: normal;}
.small_text { font-family: verdana; font-size: 10px; font-weight: normal; }
.border { border: 1px solid #045AFD;}
.border_left { border-top: 1px solid #045AFD; border-left: 1px solid #045AFD; border-right: 1px solid #045AFD;}
.border_right { border-top: 1px solid #045AFD; border-right: 1px solid #045AFD;}
.result_ok { font-family: verdana; font-size: 12px; font-weight: bold; text-align: center; color: green;}
.result_nok { font-family: verdana; font-size: 12px; font-weight: bold; text-align: center; color: red;}
.overall_ok { font-family: verdana; font-size: 12px; font-weight: bold; text-align: left; color: green;}
.overall_nok { font-family: verdana; font-size: 12px; font-weight: bold; text-align: left; color: red;}
.bborder_left { border-top: 1px solid #045AFD; border-left: 1px solid #045AFD; border-bottom: 1px solid #045AFD; background-color:#045AFD;font-family: verdana; font-size: 12px; font-weight: bold; text-align: center; color: white;}