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 ...
随机推荐
- 51nod——1432 独木桥
https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1432 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 ...
- Extjs TabPanel页签转换事件
listeners : { tabchange : function(tp, p) { var allmapDIV = document.getElementById("allmap&quo ...
- android recovery 主系统代码分析【转】
本文转载自:http://blog.csdn.net/andyhuabing/article/details/9248713 阅读完上一篇文章: http://blog.csdn.net/andyhu ...
- Android+Jquery Mobile学习系列(8)-保单/生日提醒功能
其实这个App基本功能早已做完,并且交给老婆试用去了.但由于最近项目要保证稳定,所以持续加班,没有时间写最后一点内容,本节也就简单截图做个说明,不详细叙述实现方式.我会把代码上传到最后一章中,有兴趣的 ...
- [APIO2008]DNA
https://zybuluo.com/ysner/note/1158123 题面 戳我 解析 我们要求出第\(r\)种方案,莫过于看其前面什么时候有\(r-1\)种方案. 于是,我们要求出每种情况的 ...
- MySQL:常见错误01
ylbtech-MySQL:常见错误01 1.返回顶部 1. [SQL]select * from product_product_tag aLEFT JOIN system_tag b on b.i ...
- [Apple开发者帐户帮助]三、创建证书(7)创建证书签名请求
Mac上的Keychain Access允许您创建证书签名请求(CSR). 启动位于的Keychain Access /Applications/Utilities. 选择Keychain Acces ...
- 通过JS制作一个简易数码时钟
设计思路: 数码时钟即通过图片数字来显示当前时间,需要显示的图片的URL根据时间变化而变化. a.获取当前时间Date()并将当前时间信息转换为一个6位的字符串; b.根据时间字符串每个位置对应的数字 ...
- thinkphp 上传多张图片
tp3.23 没有找到同时上传多张图片 手册有讲过:http://www.kancloud.cn/manual/thinkphp/1876 其实可以通过,多张图片多次上传来到达效果 hmlt: < ...
- Oracle_exp/expdp备份
目录索引 1.exp和expdp的区别 2.expdp导出数据库流程 一.↓↓exp和expdp的区别↓↓ 1.exp和expdp最明显的区别就是导出速度的不同.expdp导出是并行导出(如果把exp ...