watir测试报告(二)
来源:互联网 发布:pdfobject.js 兼容ie 编辑:程序博客网 时间:2024/04/18 13:22
#本文主要是生成测试报告的格式, 可以根据各自的需要进行修改。
class HTMLReport
# Initialize the report classdef initialize()
@overallResult = 'PASS'
@reportContent1 = ''
@reportContent2 = ''
@start_time = Time.now
@passed = 0
@failed = 0
end
def createReport(reportName, header, browser_type)
#此处包含生成测试报告的名字、title、浏览器的类型。
@reportName = reportName
def get_date #报告产生的日期
Time.now.strftime("%m.%d.%y")
end
def get_time
Time.now.strftime("%I.%M.%S.%p")
end
# Create the report name
d = self.get_date
t = self.get_time
strTime = "#{d}-#{t}.html"
strNiceTime = "#{d} @ #{t}"
#此处规定了测试报告生成的名字, 以及路径, 其实路径最好不好写, 以免影响其独立性。
# 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>Test Report: ' + header + '</title>
<link rel="stylesheet" type="text/css" href="../classes/css/bluegray.css">
</head>
<body>
<br />
<center>
<table width=800 border=1 cellpadding=1 cellspacing=1>
<tbody>
<tr>
<td>
<table width=100% cellpadding=2 cellspacing=2 bgcolor="#E0FFFF">
<tbody>
<tr>
<th class="header" align=center>Test Report: ' + header + '</th>
</tr>
</tbody>
</table>
<br />
<center>
<table border=1 width=95% cellpadding=1 cellspacing=1>
<tbody>
<tr>
<th width=15% bgcolor="#E0FFFF">File Name:</th>
<td width=85% colspan=5 align="center">' + reportName + '-' + strTime + '</td>
</tr>
<tr>
<th class="nobg" width=15% bgcolor="#E0FFFF">Test Date:</th>
<td width=30% align="center">' + strNiceTime + '</td>
<th class="nobg" width=15% bgcolor="#E0FFFF">Test Result:</th>'
@reportContent2 = '
</center>
<br>
<table width=95% cellpadding=2 cellspacing=1 border=1>
<tr><td>case title</td></tr>
<tr><td>test</td></tr>
</table>
<br>
<center>
<table width=95% cellpadding=2 cellspacing=1 border=1>
<tbody>
<tr bgcolor="#E0FFFF">
<th width=45%>Test Step</th>
<th width=10%>Result</th>
<th width=45%>Description</th>
</tr>'
# Close the report
strFile.close
return strTotalReport
end
def newTestName(name)
@reportContent2 = @reportContent2 + '<tr><td class ="alt" colspan="3" align="center" bgcolor="#B0C4DE">' + name + '</td></tr>'
end
def addtoReport(step, result, description)
@reportContent2 = @reportContent2 + '<tr><td class="step">' + step + '</td>'
# Format the body of the HTML report
if result == 'PASS'
@reportContent2 = @reportContent2 + '<td class="result_pass" bgcolor="green" align="center">' + result + '</td>'
@passed += 1
else
@overallResult = 'FAIL'
@reportContent2 = @reportContent2 + '<td class="result_fail" bgcolor="red" align="center">' + result + '</td>'
@failed += 1
end
@reportContent2 = @reportContent2 + ' <td class="result_text">' + description + '</td></tr>'
end
def add_to_report(result, test, pass_text, fail_text)
result == true ? self.addtoReport(test, 'PASS', pass_text) : self.addtoReport(test, 'FAIL', fail_text)
end
# formats seconds to minutes, seconds
def format_test_time(seconds)
if seconds < 60
"0 min, #{"%.02f" % seconds} sec"
else
minutes = (seconds/60).to_i
seconds = seconds - (minutes*60)
"#{minutes} min, #{"%.02f" % seconds} sec"
end
end
def finishReport(reportName, browser, env)
# Open the HTML report
strFile = File.open(reportName, 'a')
# Format the footer of the HTML report
@reportContent2 = @reportContent2 + '</table>
<br><br>
<hr width=100% size=1px>
<br />
<center><h5>©CompanyName 2009</h5></center>
<br>'
strFile.puts(@reportContent1)
total = @passed + @failed
percent_pass = ((@passed.to_f/total * 100)).to_s
percent_fail = ((@failed.to_f/total * 100)).to_s
strFile.puts('<td align="center" colspan=3>' + '<b><font color="green">' + "%.02f" % percent_pass + '% Passed, ' + '<font color="red">' + "%.02f" % percent_fail + '% Failed' + '</b></td></tr>')
# get test time
seconds = (Time.now - @start_time)
test_time = self.format_test_time(seconds)
strFile.puts('</tr>
<th width=15% bgcolor="#E0FFFF">Run time:</th>
<td width=20% align="center">' + test_time + '</td>
<th width=15% bgcolor="#E0FFFF">Browser:</th>
<td align="center" width=20%><img src="../Images/' + browser.downcase + '.gif" width=30%/></td>
<th width=10% bgcolor="#E0FFFF">Env:</th>
<td align="center">' + env + '</td>
</tr>
</tbody></table>')
strFile.puts(@reportContent2)
# Close the report
strFile.close
end
end
- watir测试报告(二)
- watir测试报告(一)
- ReportNg测试报告的定制修改(二)
- watir
- mongodb3.0 性能测试报告 二
- watir学习之旅(二):搭建Ruby集成开发环境
- watir安装备忘(Rubygem)
- 测试报告(1)
- 性能测试报告(实例)
- 性能测试报告(实例)
- 测试报告
- 测试报告
- 测试报告
- 测试报告
- 测试报告
- 测试报告
- 测试报告
- python 接口测试框架测试报告 (二)
- 经典非原创,搜集网页常用Javascript
- 五金的传统营销与网络营销的区别
- Windows下的QT 4.7.3安装教程
- qt4 udp QUdpSocket -------wireshark
- C++0x FAQ中文版 - [C++11 FAQ]
- watir测试报告(二)
- 学长的工作初感受及对IT行业的理解====看来我只能把计算机当做工具
- Python对文件及文件夹的一些操作
- 使用AVPlayer获取HTTP live stream audio文件的duration
- 谈谈汽配的网络营销
- 关于Linux下kernel.shmmax的设置问题
- javascript线程解释(setTimeout,setInterval你不知道的事)
- Smarty总结:
- 前台绑定后台 DataTable 或 泛型 等