python 生成HTmL报告页面 V1.2

上代码
# -*- coding=utf-8 -*-
import time,os #数据部分
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')} class Template_mixin(object):
"""html报告"""
HTML_TMPL = r"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自动化测试报告</title>
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<h2 style="font-family: Microsoft YaHei">自动化测试报告</h2>
<p class='attribute'><strong>测试结果 : </strong> %(value)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_tr)s
<!-- 执行模块 -->
<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_tr2)s
%(table_tr3)s </table>
</body>
</html>"""
#总数据
TABLE_TMPL_TOTAL = """
<tr class='failClass warning'>
<td>%(version)s</td>
<td>%(radio)s</td>
<td>%(runstarttime)s</td>
<td>%(runstoptime)s</td>
</tr>"""
#详情表头
TABLE_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>%(status)s</th>
</tr>"""
#case数据
TABLE_TMPL_CASE = """
<tr class='failClass warning'>
<td>%(name)s</td>
<td>%(module)s</td>
<td>%(casetotal)s</td>
<td>%(passtotal)s</td>
<td>%(status)s</td>
</tr>""" if __name__ == '__main__':
table_tr0 = ''
table_tr1=""
table_tr2="" numfail = 1
numsucc = 9
html = Template_mixin() #总表数据
table_td = html.TABLE_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.TABLE_TMPL_MODULE % dict(name="",module=case1["name"],casetotal=case1["total"],passtotal=case1["passnum"],status=case1["status"],)
table_tr1 += table_td_module #表头总数
total_str = '共 %s,通过 %s,失败 %s' % (numfail + numsucc, numsucc, numfail) #case数据
table_td_case=html.TABLE_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(value = total_str,table_tr = table_tr0,table_tr2=table_tr1,table_tr3=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')
filename=os.path.join(dir,filename) with open(filename, 'wb') as f:
f.write(output.encode('utf8'))
python 生成HTmL报告页面 V1.2的更多相关文章
- python 生成HTmL报告页面 V1.3 修改字体颜色
HTML报告V1.3 根据文字内容显示不同的字体颜色: 代码如下: # -*- coding=utf-8 -*- import time,os """ V1.2 1.生成 ...
- python 生成HTmL报告页面
计划做一个html页面 py3.4 代码: # -*- coding=utf-8 -*- # import time,os class Template_mixin(object): "&q ...
- html 报告页面 v1.2 批量数据生成表格
html 报告页面 v1.2 批量数据生成表格 上代码: <!DOCTYPE html> <html lang="en"> <head> < ...
- python生成HTMl报告(unittest)
Python3 使用HTMLTestRunner.py 报错ImportError: No module named 'StringIO'处理方法 HTMLTestRunner.py文件是基于Py ...
- python生成pdf报告、python实现html转换为pdf报告
1.先说下html转换为pdf:其实支持直接生成,有三个函数pdfkit.f 安装python包:pip Install pdfkit 系统安装wkhtmltopdf:参考 https://githu ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告
1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请求参数 ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(二)
可以参考 python+requests接口自动化完整项目设计源码(一)https://www.cnblogs.com/111testing/p/9612671.html 原文地址https://ww ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(已弃用)
前言 1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请 ...
- 利用Python半自动化生成Nessus报告
0x01 前言 Nessus是一个功能强大而又易于使用的远程安全扫描器,Nessus对个人用户是免费的,只需要在官方网站上填邮箱,立马就能收到注册号了,对应商业用户是收费的.当然,个人用户是有16个I ...
随机推荐
- Bitnami LNMP集成包安装简单总结
前言发送图文消息时间点,访问量大,请求并发多,业务web机处理不过来,新增加了2台web机应对.搞过Linux软件安装的都知道,各种库的依赖会把人搞崩溃,尤其是服务器不能访问外网的情况下,会非常的蛋疼 ...
- Source Insight 与 Source Navigator ,Understand ,Crystal FLOW 源代码阅读工具
http://www.sourceinsight.com/update.html http://www.oschina.net/p/sourcenavigator/ http://www.cnblog ...
- [转]C#操作SQL Server数据库
转自:C#操作SQL Server数据库 1.概述 ado.net提供了丰富的数据库操作,这些操作可以分为三个步骤: 第一,使用SqlConnection对象连接数据库: 第二,建立SqlComman ...
- Clojure:两步发送iOS推送通知(apns)
首先在project.clj中,添加对notnoop 类库的引用:[com.notnoop.apns/apns "0.2.3"] 然后使用如下方法就可以发送推送消息了: (ns d ...
- Spark 颠覆 MapReduce 保持的排序记录
在过去几年,Apache Spark的採用以惊人的速度添加着,通常被作为MapReduce后继,能够支撑数千节点规模的集群部署. 在内存中数 据处理上,Apache Spark比MapReduce更加 ...
- php session自定义处理
原文:http://www.cnblogs.com/mrcoke/ 这个人的博客上转的. 这个博客也好: 学算法和数据结构!!http://blog.csdn.net/21aspnet/articl ...
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
完整错误信息: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS" AND ANY ...
- 对于HBase的MapReduce性能提升方案之BulkLoad
我们知道,在第一次海量数据批量入库时,我们会选择使用BulkLoad的方式. 简单介绍一下BulkLoad原理方式:(1)通过MapReduce的方式,在Map或者Reduce端将输出格式化为HBas ...
- 使用oracle数据库和MySQL数据库时hibernate的映射文件.hbm.xml的不同
假设是使用oracle数据库.那么hibernate的映射文件.hbm.xml例如以下: <id name="xuehao" column="xuehao" ...
- Android studio第一次使用配置(三)gradle项目构建
1.gradle的概念 2.gradle配置jar包.和libs目录导入jar包的差别 3.签名打包: (1)Studio (2)命令行 (3)gradle wrapper的原理 4.BuildCon ...