zoukankan      html  css  js  c++  java
  • python生成html报告

    class Template_mixin(object):
        """html报告"""
        HTML_TMPL = """
            <!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">
                <h1 style="font-family: Microsoft YaHei">自动化测试报告</h1>
                <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
                </table>
            </body>
            </html>"""
       
        TABLE_TMPL = """
            <tr class='failClass warning'>
                <td>%(step)s</td>
                <td>%(runtime)s</td>
                <td>%(runresult)s</td>
                <td>%(reason)s</td>
            </tr>"""

    if __name__ == '__main__':

      table_tr0 = ''

      numfail = 1

      numsucc = 9
           html = Template_mixin()

      table_td = html.TABLE_TMPL % dict(
                                                          step='1',
                                                          runtime=datetime.datetime.now(),
                                                          runresult='Fail',
                                                          reason='失败或成功原因',
                                                          )
           table_tr0 += table_td 

      total_str = '共 %s,通过 %s,失败 %s' % (numfail + numsucc, numsucc, numfail)
           output = html.HTML_TMPL % dict(
                                                      value = total_str,
                                                    table_tr = table_tr0,
                                                    )

      #生成html报告

      with open("Decision_KKD.html",'wb') as f:
                    f.write(output.encode('utf-8'))

  • 相关阅读:
    Java多线程编程核心技术---对象及变量的并发访问(二)
    Java多线程编程核心技术---对象及变量的并发访问(一)
    Java多线程编程核心技术---Java多线程技能
    普通浏览器GET请求与Ajax的GET请求的区别
    【python】-- 面向对象引子、概念
    【python】-- json & pickle、xml、requests、hashlib、shelve、shutil、configparser、subprocess
    【python】-- 内置函数、软件目录开发规范(代码编码风格)
    【python】-- 装饰器、迭代器、生成器
    【python】-- 递归函数、高阶函数、嵌套函数、匿名函数
    【python】-- 函数非固定参数,返回值(return)
  • 原文地址:https://www.cnblogs.com/sammy1989/p/7598141.html
Copyright © 2011-2022 走看看