HTML报告V1.3 根据文字内容显示不同的字体颜色:

代码如下:

 # -*- coding=utf-8 -*-
import time,os """
V1.2
1.生成total表格
2.生成report表格
3.生成module表格
4.生成case表格 """
#----数据部分-------------------------------------------
func_dict={"funcname":"模块1",} funcname=['书架','书城','分类','我的']
case1={"name":"模块1","total":"","passnum":"","failnum":"","radio":"","status":"PASS"}
case2={"name":"模块2","total":"","passnum":"","failnum":"","radio":"","status":"Fail"} VERSION_DICT={"version": '快看小说 3.8.8',"radio":'',"runstarttime":time.strftime('%Y-%m-%d %H:%M:%S'),"runstoptime" : time.strftime('%Y-%m-%d %H:%M:%S')} #---END------------------------------------------- class Template_mixin(object):
"""html报告"""
# ------------------------------------------------------------------------
# HTML Template
HTML_TMPL = r"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>%(title)s</title>
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<h2 style="font-family: Microsoft YaHei">%(title)s</h2> <p class='attribute'><strong>测试结果 : </strong> %(total)s</p>
<style type="text/css" media="screen">
body { font-family: Microsoft YaHei,Tahoma,arial,helvetica,sans-serif;padding: 20px;}
</style>
</head>
<body>
<table id='result_table' class="table table-condensed table-bordered table-hover">
<colgroup>
<col align='left' />
<col align='right' />
<col align='right' />
<col align='right' />
</colgroup>
<tr id='header_row' class="text-center success" style="font-weight: bold;font-size: 14px;">
<th>客户端及版本</th>
<th>通过率</th>
<th>开始时间</th>
<th>结束时间</th>
</tr>
%(table_total)s </table>
<!-- 执行模块 -->
<p class='attribute'><strong>测试报告详情 : </strong> </p>
<table id='result_table' class="table table-condensed table-bordered table-hover">
<colgroup>
<col align='left' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
</colgroup>
<tr id='header_row' class="text-center success" style="font-weight: bold;font-size: 14px;">
<th colspan="2">业务模块</th>
<th>用例总数</th>
<th>通过数</th>
<th>状态</th>
</tr>
%(table_module)s
%(table_case)s </table>
<script type="text/javascript">
//change color
//取都用demo的多组
var eles = document.getElementsByClassName('demo');
console.log(eles);
var x=document.getElementById("demo").innerText;
console.log("the value is :"+x);
//每组都应用样式
for(var i = 0; i < eles.length; i++){
if(eles[i].innerText == 'PASS'){
eles[i].style.color = 'green';
}else{
eles[i].style.color = 'red';
}
} </script> </body>
</html>"""
# variables: (title,total, table_total,table_module,table_case) # ------------------------------------------------------------------------
# Report #总数据
REPORT_TMPL_TOTAL = """
<tr class='failClass warning'>
<td>%(version)s</td>
<td>%(radio)s</td>
<td>%(runstarttime)s</td>
<td>%(runstoptime)s</td>
</tr>""" #详情表头
REPORT_TMPL_MODULE = """
<tr id='header_row' class="text-center success" style="font-weight: bold;font-size: 14px;">
<th>%(name)s</th>
<th>%(module)s</th>
<th>%(casetotal)s</th>
<th>%(passtotal)s</th>
<th class='demo' id="demo">%(status)s</th>
</tr>""" #case数据
REPORT_TMPL_CASE = """
<tr class='failClass warning'>
<td>%(name)s</td>
<td>%(module)s</td>
<td>%(casetotal)s</td>
<td>%(passtotal)s</td>
<td class='demo' id="demo2">%(status)s</td>
</tr>""" if __name__ == '__main__':
table_tr0 = ''
table_tr1=""
table_tr2="" numfail = 1
numsucc = 9
html = Template_mixin() #总表数据
table_td = html.REPORT_TMPL_TOTAL % dict(version=VERSION_DICT['version'],radio=VERSION_DICT['radio'],runstarttime=VERSION_DICT['runstarttime'],runstoptime = VERSION_DICT['runstoptime'])
table_tr0 += table_td #详情数据
table_td_module=html.REPORT_TMPL_MODULE % dict(name="",module=case1["name"],casetotal=case1["total"],passtotal=case1["passnum"],status=case1["status"],)
table_tr1 += table_td_module
#title
title_str="自动化测试报告"
#表头总数
total_str = '共 %s,通过 %s,失败 %s' % (numfail + numsucc, numsucc, numfail) #case数据
table_td_case=html.REPORT_TMPL_CASE % dict(name="",module=case2["name"],casetotal=case2["total"],passtotal=case2["passnum"],status=case2["status"],)
table_tr2 += table_td_case output=html.HTML_TMPL % dict(title=title_str,total = total_str,table_total = table_tr0,table_module=table_tr1,table_case=table_tr2) # 生成html报告
filename='{date}_TestReport.html'.format(date=time.strftime('%Y%m%d%H%M%S')) print(filename)
#获取report的路径
dir= os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),'report/html')
filename=os.path.join(dir,filename) with open(filename, 'wb') as f:
f.write(output.encode('utf8'))

下一个版本,想要实现caselist批量生成表格。

python 生成HTmL报告页面 V1.3 修改字体颜色的更多相关文章

  1. python 生成HTmL报告页面 V1.2

    上代码 # -*- coding=utf-8 -*- import time,os #数据部分 func_dict={"funcname":"模块1",} fu ...

  2. python 生成HTmL报告页面

    计划做一个html页面 py3.4 代码: # -*- coding=utf-8 -*- # import time,os class Template_mixin(object): "&q ...

  3. html 报告页面 v1.2 批量数据生成表格

    html 报告页面 v1.2 批量数据生成表格 上代码: <!DOCTYPE html> <html lang="en"> <head> < ...

  4. python生成HTMl报告(unittest)

      Python3 使用HTMLTestRunner.py 报错ImportError: No module named 'StringIO'处理方法 HTMLTestRunner.py文件是基于Py ...

  5. 【纯代码】Swift-自定义PickerView单选(可修改分割线颜色、修改字体大小、修改字体颜色。)(可根据需要自己扩展)

    typealias PopPickerViewCallBackClosure = (_ resultStr:NSString?) -> () class PopPickerView : UIVi ...

  6. layer ui插件显示tips时,修改字体颜色

    今天做调查问卷,又遇到一个蛋疼小问题,记录下. 调查问卷有很多选项是要求必填的,如果不填的话,需要给出友好的提示.用的如下组件:http://layer.layui.com/ 1.之前一直默认用的: ...

  7. 关于无法使用python执行进入百度页面的代码修改

    前几天听了个坑爹的视频教学,按照你们的方法做了,但尼玛,执行下来各种问题啊: 首先进入页面,总是提示开发者模式,删了下次执行又挂了,于是乎我就找网上帖子解决问题,果然被我解决了 先装这两个文件,把浏览 ...

  8. python生成pdf报告、python实现html转换为pdf报告

    1.先说下html转换为pdf:其实支持直接生成,有三个函数pdfkit.f 安装python包:pip Install pdfkit 系统安装wkhtmltopdf:参考 https://githu ...

  9. ActionBar修改字体颜色

    style: <resources xmlns:android="http://schemas.android.com/apk/res/android"> <!- ...

随机推荐

  1. C#实现所有经典排序算法汇总

    C#实现所有经典排序算法1.选择排序 class SelectionSorter { private int min; public void Sort(int[] arr) { ; i < a ...

  2. P1464 Function 洛谷

    https://www.luogu.org/problem/show?pid=1464 题目描述 对于一个递归函数w(a,b,c) 如果a<=0 or b<=0 or c<=0就返回 ...

  3. 修改 db_unique_name

    在创建DB的时候 db_unique_name设置错了.本来我是想让 db_name=itid db_unique_name=itid1 不过想改回来很简单的. SQL> alter syste ...

  4. [PWA] Show Notifications when a Service Worker is Installed or Updated

    Service Workers get installed and activated in the background, but until we reload the page they don ...

  5. URAL 1196. History Exam (二分)

    1196. History Exam Time limit: 1.5 second Memory limit: 64 MB Professor of history decided to simpli ...

  6. HTTP服务端JSON服务端

    HTTP服务端JSON服务端 最后更新日期:  2014-5-18 Author: Kagula 阅读前提: CMake工具的基本使用 内容简介: CPPCMS是个开源Web开发框架,通过它可以很容易 ...

  7. IJ-Error:常见错误

    ylbtech-IJ-Error:常见错误 1.返回顶部 1. This application has no explicit mapping for /error, so you are seei ...

  8. 感知器算法 C++

    We can estimate the weight values for our training data using stochastic gradient descent. Stochasti ...

  9. Java 最基础的三种排序排序

    主要讲五个排序,冒泡排序.选择排序.插入排序 1)冒泡排序 /** * 冒泡排序 (默认升序排) * 相邻两个相比较,较大的向后放,从数组或者集合中的第一个与第二个比较到倒数第二个与最后一个比较为一轮 ...

  10. WebService开发-CXF

    Web Service 开发方式 Apache CXF 一.关于Apache CXF 在网址http://cxf.apache.org/可以查看到关于Apache CXF的下载及文档介绍,这里不再多做 ...