Module: ReportHelper
- Defined in:
- lib/common/report_helper.rb
Overview
测试报告生成工具类
Instance Method Summary collapse
-
#report_create(title, testResults) ⇒ Object
功能: 测试报告生成工具类,输入相关的报告数据,在当前case目录下自动生成html报告 === 参数解释: testResults = Array[ => “用例名1”, “case_direction” => “用例说明1”, “case_detail”=>“case执行信息1”, “case_result”=>“case执行结果1”, => “用例名2”, “case_direction” => “用例说明2”, “case_detail”=>“case执行信息2”, “case_result”=>“case执行结果2” ].
Instance Method Details
#report_create(title, testResults) ⇒ Object
功能:
测试报告生成工具类,输入相关的报告数据,在当前case目录下自动生成html报告
参数解释:
testResults = Array[
{"case_name" => "用例名1",
"case_direction" => "用例说明1",
"case_detail"=>"case执行信息1",
"case_result"=>"case执行结果1"},
{"case_name" => "用例名2",
"case_direction" => "用例说明2",
"case_detail"=>"case执行信息2",
"case_result"=>"case执行结果2"}
]
Example:
Example #1:
title = “大促主会场检查测试报告” testResults = Array[
{"case_name" => "test_case1",
"case_direction" => "定金规则校验",
"case_detail"=>"商品优惠价为xxx,定金为xxxx,预期为xxx,不符合预期",
"case_result"=>"warning"},
{"case_name"=>"test_case2",
"case_direction"=>"价格校验",
"case_detail"=>"Pass! 商品原价xxx VS 优惠价xxxx",
"case_result"=>"pass"}
]
report_create(title, testResults)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/common/report_helper.rb', line 42 def report_create(title,testResults) #TODO html_content = "<!DOCTYPE html><html><head> <style> table { border-collapse: collapse; } table,th,td { border:1px solid #AAAAAA; font-size:14px; height:50px; } th { background-color:#CCDDFF; font-size:16px; } td { font-size:14px; } </style> <title> #{title} </title></head><body><p>#{title}</p><div><table border=\"1\" > <tr>\ <th>case名</th>\ <th>case说明</th>\ <th>case执行详情</th>\ <th>case结果</th>\ </tr>" for num in 0..(testResults.length-1) html_content += "<tr><td> #{testResults[num]["case_name"]} </td>\ <td> #{testResults[num]["case_direction"]} </td>\ <td> #{testResults[num]["case_detail"]} </td>\ <td> #{testResults[num]["case_result"]} </td>\ </tr>" end puts html_content += "</table><div></body></html>" time = Time.new.strftime("%Y%m%d%H%M%S") file = File.new("testresult_#{time}.html","w") file.puts html_content file.close end |