python修改html页面内容_python 生成HTmL报告页面 V1.3 修改字体颜色

1 #-*- coding=utf-8 -*-

2 importtime,os3

4 """

5 V1.26 1.生成total表格7 2.生成report表格8 3.生成module表格9 4.生成case表格10

11

12 """

13 #----数据部分-------------------------------------------

14 func_dict={"funcname":"模块1",}15

16 funcname=['书架','书城','分类','我的']17 case1={"name":"模块1","total":"10","passnum":"10","failnum":"0","radio":"80","status":"PASS"}18 case2={"name":"模块2","total":"20","passnum":"15","failnum":"5","radio":"75","status":"Fail"}19

20 VERSION_DICT={"version": '快看小说 3.8.8',"radio":'99',"runstarttime":time.strftime('%Y-%m-%d %H:%M:%S'),"runstoptime" : time.strftime('%Y-%m-%d %H:%M:%S')}21

22 #---END-------------------------------------------

23

24 classTemplate_mixin(object):25 """html报告"""

26 #------------------------------------------------------------------------

27 #HTML Template

28 HTML_TMPL = r"""

29 30 31

32 33 %(title)s34 35

%(title)s

36

37

测试结果 : %(total)s

38 41 42 43
客户端及版本通过率开始时间结束时间

58

59 60

测试报告详情 :

61
业务模块用例总数通过数状态

78

79

80 97

98 99 """

100 #variables: (title,total, table_total,table_module,table_case)

101

102 #------------------------------------------------------------------------

103 #Report

104

105 #总数据

106 REPORT_TMPL_TOTAL = """

107

108 %(version)s109 %(radio)s110 %(runstarttime)s111 %(runstoptime)s112 """

113

114 #详情表头

115 REPORT_TMPL_MODULE = """

116

117 %(name)s118 %(module)s119 %(casetotal)s120 %(passtotal)s121 %(status)s122 """

123

124 #case数据

125 REPORT_TMPL_CASE = """

126

127 %(name)s128 %(module)s129 %(casetotal)s130 %(passtotal)s131 %(status)s132 """

133

134

135

136 if __name__ == '__main__':137 table_tr0 = ''

138 table_tr1=""

139 table_tr2=""

140

141 numfail = 1

142 numsucc = 9

143 html =Template_mixin()144

145 #总表数据

146 table_td = html.REPORT_TMPL_TOTAL % dict(version=VERSION_DICT['version'],radio=VERSION_DICT['radio'],runstarttime=VERSION_DICT['runstarttime'],runstoptime = VERSION_DICT['runstoptime'])147 table_tr0 +=table_td148

149 #详情数据

150 table_td_module=html.REPORT_TMPL_MODULE % dict(name="",module=case1["name"],casetotal=case1["total"],passtotal=case1["passnum"],status=case1["status"],)151 table_tr1 +=table_td_module152 #title

153 title_str="自动化测试报告"

154 #表头总数

155 total_str = '共 %s,通过 %s,失败 %s' % (numfail +numsucc, numsucc, numfail)156

157 #case数据

158 table_td_case=html.REPORT_TMPL_CASE % dict(name="",module=case2["name"],casetotal=case2["total"],passtotal=case2["passnum"],status=case2["status"],)159 table_tr2 +=table_td_case160

161 output=html.HTML_TMPL % dict(title=title_str,total = total_str,table_total = table_tr0,table_module=table_tr1,table_case=table_tr2)162

163 #生成html报告

164 filename='{date}_TestReport.html'.format(date=time.strftime('%Y%m%d%H%M%S'))165

166 print(filename)167 #获取report的路径

168 dir= os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),'report/html')169 filename=os.path.join(dir,filename)170

171 with open(filename, 'wb') as f:172 f.write(output.encode('utf8'))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值