python自动化测试模板

1:准备html模版

|----------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <!``DOCTYPE html> <``html``> <``head``> ``<``meta charset="utf-8"> ``<``title``>接口自动化</``title``> </``head``> <``body style="margin-top: 20px; font-style: '微软雅黑';"> <``table border="1" cellspacing="0" cellpadding="5" width="100%" align="center"> ``<``tr bgcolor="bisque" style="font-style: 30px"> ``<``td height="60" colspan="5"> ``自动化测试报告:&test_data ``</``td``> ``</``tr``> ``<``tr style="font-style: 20px"> ``<``td width="20%">被测版本:&version</``td``> ``<``td width="15%">成功:&pass</``td``> ``<``td width="15%">失败:&fail</``td``> ``<``td width="15%">错误:&error</``td``> ``<``td width="30%">最后时间:&lasttime</``td``> ``</``tr``> </``table``> <``p``></``p``> <``table border="1" cellspacing="0" cellpadding="5" width="100%" align="center"> ``<``tr height="40" bgcolor="darkseagreen"> ``<``td width="7%">记录编号:</``td``> ``<``td width="10%">记录编号:</``td``> ``<``td width="9%">记录编号:</``td``> ``<``td width="7%">记录编号:</``td``> ``<``td width="20%">记录编号:</``td``> ``<``td width="7%">记录编号:</``td``> ``<``td width="15%">记录编号:</``td``> ``<``td width="15%">记录编号:</``td``> ``<``td width="10%">记录编号:</``td``> ``<``td width="10%">记录编号:</``td``> ``</``tr``> ``&test_result </``table``> </``body``> </``html``> |

打开模版,数据替换

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | ''' Created on Aug 8, 2019 @author: liliang ''' import os import time from ctypes.test.test_pickling ``import name class MyClass(): ``''' ``classdocs ``''' ``def __init__(``self``): ``pass ``def open_file(``self``): ``tempfile``=``os.path.abspath(``".."``)``+``"/demo/2.html" ``tem``=``open``(tempfile, mode``=``'r'``, encoding``=``'utf-8'``).read() ``return tem ``def write_file(``self``,``file``,test_data,version,passnum,faillnum,errornum,lasttime,all_data): ``file``=``file``.replace(``"&test_data"``,test_data) ``file``=``file``.replace(``"&version"``,version) ``file``=``file``.replace(``'&pass'``,passnum) ``file``=``file``.replace(``'&fail'``,faillnum) ``file``=``file``.replace(``'&error'``,errornum) ``file``=``file``.replace(``'&lasttime'``,lasttime) ``content``=``'' ``for i ``in range``(``0``,``len``(all_data)): ``if all_data[i][``"name"``] ``=``=``"粉丝"``: ``content``+``=``"<tr height=40 bgcolor='red'>" ``content``+``=``"<td width='7%%' >%s</d>" %``str``(all_data[i][``"name"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"age"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"sex"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"school"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"work"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"address"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"sex1"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"school2"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"work3"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"address4"``]) ``content``+``=``"</tr>" ``else``: ``content``+``=``"<tr height=40 bgcolor='bisque'>" ``content``+``=``"<td width='7%%' >%s</d>" %``str``(all_data[i][``"name"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"age"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"sex"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"school"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"work"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"address"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"sex1"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"school2"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"work3"``]) ``content``+``=``"<td width='7%%'>%s</d>" %``str``(all_data[i][``"address4"``]) ``content``+``=``"</tr>" # for result in all_data: # content+="<tr height=40>" # content+="<td width='7%%'>%s</d>" %str(result[0]) # content+="<td width='7%%'>%s</d>" %str(result[1]) # content+="<td width='7%%'>%s</d>" %str(result[2]) # content+="<td width='7%%'>%s</d>" %result[3] # content+="<td width='7%%'>%s</d>" %result[4] # content+="<td width='7%%'>%s</d>" %result[5] # content+="<td width='7%%'>%s</d>" %result[6] # content+="<td width='7%%'>%s</d>" %result[7] # content+="<td width='7%%'>%s</d>" %result[8] # content+="<td width='7%%'>%s</d>" %result[9] # content+="</tr>" ``file``=``file``.replace(``'&test_result'``,content) ``file_folder``=``os.path.abspath(``".."``)``+``"/demo/" ``file_name``=``file_folder``+``time.strftime(``"%Y-%m-%d %H:%M:%S"``,time.localtime())``+``".html" ``report_file``=``open``(file_name, mode``=``"w+"``, encoding``=``'utf-8'``) ``report_file.write(``file``) ``report_file.close() ``def get_datetime(``self``): ``now_time``=``time.strftime(``"%Y_%M_%d_%H:%M:%S"``,time.localtime()) ``return now_time if __name__ ``=``= '__main__'``: ``my``=``MyClass() ``file``=``my.open_file() ``all_data``=``[ ``{``"name"``:``"Tom"``,``"age"``:``23``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小学2"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"数据"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小3学"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"粉丝"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小学4"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"阿道夫"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小fs学"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"二娃"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小学fa"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"我确认"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小学"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"特务"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小学fa"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"突然"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小学ddd"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"圈儿"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小asss学"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``{``"name"``:``"让他"``,``"age"``:``"13"``,``"sex"``:``"男"``,``"school"``:``"希望小学"``,``"work"``:``"学生"``,``"address"``:``"上海"``,``"sex1"``:``"男"``,``"school2"``:``"希望小学fdsaa"``,``"work3"``:``"学生"``,``"address4"``:``"上海"``}, ``] ``my.write_file(``file``, ``"2019_07_08_03:07:59"``, ``"1.3.0"``, ``"90"``, ``"7"``, ``"key error"``, ``"2019_07_08_03:07:59"``, all_data) |

|---|-----------|
| 1 | ``生成报告 |

工程目录

Python接口自动化测试零基础入门到精通(2023最新版)

相关推荐
“AI国潮设计-小江”2 分钟前
【AIGC实战】Python+SDXL批量生成“潮汕英歌舞不倒翁”IP | 角色一致性与多场景融合方案,附完整代码
开发语言·人工智能·python·prompt·aigc
传奇开心果编程8 分钟前
【Rust入门练中学】第6课:结构体与方法
开发语言·rust·结构体·编程语言理论·结构体方法·编程通用语言
Linux_cy11 分钟前
服务器管理工具哪个好用?我用了七八个
运维·服务器·javascript·python·ssh·面板·gmssh
MoRanzhi120318 分钟前
第6篇(下)· 使用 PyQt5 实现 2048 高性能计算版:统一运行控制与跨模式安全交接
python·pyqt·进程管理·状态机·软件架构·并发控制·数据一致性
code tsunami36 分钟前
【无标题】
开发语言·python
春弦_41 分钟前
自用算法整理二
数据结构·算法·图论
CodeGL1 小时前
10、Python基础之进程和线程
开发语言·python
hetao17338372 小时前
2026-10-22~23 hetao1733837 的刷题记录
c++·算法
TechWayfarer2 小时前
PHP漏洞被利用,怎么揪出攻击IP?
开发语言·python·tcp/ip·网络安全·php
java_nnnn2 小时前
LeetCode刷题滑动窗口(串联所有单词的子串+最小覆盖的子串)Java
算法·leetcode·职场和发展