20191011-构建我们公司自己的自动化接口测试框架-Util的htmlreport模块

生成htmlreport的模块是我在网上随意找的一个版本,主要生成的report包括接口名称,接口url,请求数据,响应数据,断言词,断言结果等

 

 具体的htmlreport代码如下:

# -*- encoding:utf-8 -*-

from bottle import template

def report_html(data,html_name):
    template_demo = """
    <!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.hovertable {
    font-family: verdana,arial,sans-serif;
    font-size:11px;
    color:#333333;
    border-width: 1px;
    border-color: #999999;
    border-collapse: collapse;
}
table.hovertable th {
    background-color:#ff6347;
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #a9c6c9;
}
table.hovertable tr {
    background-color:#d4e3e5;
}
table.hovertable td {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #a9c6c9;
}
</style>

<!-- Table goes in the document BODY -->

<head>

<meta http-equiv="content-type" content="txt/html; charset=utf-8" />

</head>

<table class="hovertable">
<tr>
    <th>接口名称</th><th>接口 URL</th><th>请求数据</th><th>接口响应数据</th><th>接口调用耗时(单位:ms)</th><th>断言表</th><th>测试结果</th>
</tr>
% for name,url,request_data,response_data,test_time,assert_word,result in items:
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">

    <td>{{name}}</td><td>{{url}}</td><td>{{request_data}}</td><td>{{response_data}}</td><td>{{test_time}}</td><td>{{assert_word}}</td><td>
    % if result == '失败':
    <font color=red>
    % end
    {{result}}</td>
</tr>
% end
</table>
    """
    html = template(template_demo, items=data)
    with open(html_name+".html", 'wb') as f:
        f.write(html.encode('utf-8'))


if __name__ == '__main__':
    data = [("API",'http://39.106.41.11:8080/register/', '{"username": "tiansl2831", "password": "wulaoshi123451", "email": "wulaoshi@qq.com"}', '{"username": "tiansl2831", "code": "01"}',"5ms","00", '成功')]
    html_name = '接口测试报告'
    report_html(data,html_name)

 

posted @ 2019-10-11 15:57  何发奋  阅读(219)  评论(0编辑  收藏  举报