blob: 01c3392720b5e6726572043be3128cd2f517cfa9 [file] [log] [blame]
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Defines a HTML template for reporting Franky test results.
"""
# ----------------------------------------------------------------------
# Template
class HTMLTemplate(object):
"""Defines a HTML template for reporting test results.
Overall structure of the HTML report.
HTML
+------------------------+
|<html> |
| <head> |
| |
| STYLESHEET |
| +----------------+ |
| | | |
| +----------------+ |
| |
| </head> |
| |
| <body> |
| |
| HEADING |
| +----------------+ |
| | | |
| +----------------+ |
| |
| REPORT |
| +----------------+ |
| | | |
| +----------------+ |
| |
| ENDING |
| +----------------+ |
| | | |
| +----------------+ |
| |
| </body> |
|</html> |
+------------------------+
"""
STATUS = {
0: 'pass',
1: 'fail',
}
DEFAULT_TITLE = 'Franky Dashboard'
DEFAULT_DESCRIPTION = 'No Report Description'
# ------------------------------------------------------------------------
# HTML Template
HTML_TMPL = """
<!doctype html>
<head>
<title>%(title)s</title>
<meta name="generator" content="%(generator)s"/>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8"/>
%(stylesheet)s
</head>
<body>
<script language="javascript" type="text/javascript"><!--
%(script)s
--></script>
%(heading)s
%(report)s
%(ending)s
</body>
</html>
"""
# variables: (title, generator, stylesheet, heading, report, ending)
# ------------------------------------------------------------------------
# Stylesheet
STYLESHEET_TMPL = """<style type="text/css" media="screen">
body { font-family: verdana, arial, helvetica,
sans-serif; font-size: 80%; }
table { font-size: 100%; }
pre { }
/* -- heading ---------------------------------------- */
h1 {
font-size: 16pt;
color: blue;
}
.heading {
margin-top: 0ex;
margin-bottom: 1ex;
}
.heading .attribute {
margin-top: 1ex;
margin-bottom: 0;
}
.heading .description {
margin-top: 4ex;
margin-bottom: 6ex;
}
/* -- css div popup ---------------------------------- */
a.popup_link {
}
a.popup_link:hover {
color: red;
}
.popup_window {
display: none;
position: relative;
left: 0px;
top: 0px;
padding: 10px;
background-color: #E6E6D6;
font-family: "Lucida Console", "Courier New", Courier,
monospace;
text-align: left;
font-size: 8pt;
width: 500px;
}
#close_window {
text-align: right;
color: red;
cursor: pointer;
}
/* -- report --------------------------------------- */
#show_detail_line {
margin-top: 3ex;
margin-bottom: 1ex;
}
#result_table {
width: 80%;
border-collapse: collapse;
border: 1px solid #777;
}
#header_row {
font-weight: bold;
color: white;
background-color: #777;
}
#result_table td {
border: 1px solid #777;
padding: 2px;
}
#total_row { font-weight: bold; }
.passClass { background-color: #6c6; }
.failClass { background-color: #c00; }
.passCase { color: #6c6; }
.failCase { color: #c00; font-weight: bold; }
.hiddenRow { display: none; }
.testcase { margin-left: 2em; }
/* -- ending ----------------------------------------- */
#ending {
}
</style>
"""
# ------------------------------------------------------------------------
# Heading
#
# variables: (title, parameters, description)
HEADING_TMPL = """<div class='heading'>
<h1>%(title)s</h1>
%(parameters)s
<p class='description'>%(description)s</p>
</div>
"""
# variables: (name, value)
HEADING_ATTRIBUTE_TMPL = """<p class='attribute'><strong>%(name)s:</strong>
%(value)s</p>
"""
# ------------------------------------------------------------------------
# Report
#
# variables: (test_list, count, Pass, fail)
REPORT_TMPL = """
<p id='show_detail_line'>Show
<a href='javascript:showCase(0)'>Summary</a>
<a href='javascript:showCase(1)'>Failed</a>
<a href='javascript:showCase(2)'>All</a>
</p>
<table id='result_table'>
<colgroup>
<col align='left' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
</colgroup>
<tr id='header_row'>
<th align='left'>Test Group/Test case</th>
<th align='left'>Count</th>
<th align='left'>Pass</th>
<th align='left'>Fail</th>
<th align='left'>View</th>
</tr>
%(test_list)s
<tr id='total_row'>
<th align='left'>Total</th>
<th align='left'>%(Count)s</th>
<th align='left'>%(Pass)s</th>
<th align='left'>%(Fail)s</th>
<th align='left'>&nbsp;</th>
</tr>
</table>
"""
# variables: (style, Count, Pass, Fail)
REPORT_CLASS_TMPL = """
<tr class='%(style)s'>
<th align='left'>Description</th>
<th align='left'>%(Count)s</th>
<th align='left'>%(Pass)s</th>
<th align='left'>%(Fail)s</th>
<th align='left'><a href="javascript:showReportDetail(
%(Count)s)">
Detail</a></th>
</tr>
"""
# variables: (test_id, class_, style, desc, status)
REPORT_OUTPUT_TMPL = """
<tr id='%(test_id)s' class='%(class_)s'>
<td class='%(style)s'>
<div class='testcase'>%(desc)s</div>
</td>
<td colspan='5' align='center'>
<a class="popup_link" onfocus='this.blur();'
href="javascript:showTestDetail('div_%(test_id)s')" >
%(status)s
</a>
<div id='div_%(test_id)s' class="popup_window">
<div id='close_window'>
<a onfocus='this.blur();'
onclick="document.getElementById('div_%(test_id)s')
.style.display = 'none'" >[x]
</a>
</div>
<pre>
%(script)s
</pre>
</div>
</td>
</tr>
"""
# variables: (id, output)
REPORT_TEST_OUTPUT_TMPL = r"""%(id)s: %(output)s"""
# ------------------------------------------------------------------------
# ENDING
#
ENDING_TMPL = """<div id='ending'>&nbsp;</div>"""
JSCRIPT = """
/* level - 0:Summary; 1:Failed; 2:All */
function showCase(level) {
var trs = document.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++) {
var tr = trs[i];
var id = tr.id;
if (id.indexOf('failed') != -1) {
if (level < 1) {
tr.className = 'hiddenRow';
}
else {
tr.className = '';
}
}
if (id.indexOf('passed') != -1) {
if (level > 1) {
tr.className = '';
}
else {
tr.className = 'hiddenRow';
}
}
}
}
function showReportDetail(count) {
var id_list = [count];
var toHide = 1;
for (var i = 0; i < count; i++) {
var partial_test_id = 'Test ' + (i+1) + ' ';
var test_id = partial_test_id + 'failed';
var tr = document.getElementById(test_id);
if (!tr) {
test_id = partial_test_id + 'passed';
tr = document.getElementById(test_id);
}
id_list[i] = test_id;
if (tr.className) {
toHide = 0;
}
}
for (var j = 0; j < count; j++) {
var full_test_id = id_list[j];
if (toHide) {
document.getElementById('div_'+full_test_id).style.display =
'none';
document.getElementById(full_test_id).className =
'hiddenRow';
}
else{
document.getElementById(full_test_id).className = '';
}
}
}
function showTestDetail(div_id) {
var details_div = document.getElementById(div_id);
var displayState = details_div.style.display;
if (displayState != 'block') {
displayState = 'block';
details_div.style.display = 'block';
}
else {
details_div.style.display = 'none';
}
}
"""