python 生成HTmL報告頁面 V1 2

2022-08-13 17:39:22 字數 3294 閱讀 8140

上**

1

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

2import

time,os34

#資料部分

5 func_dict=

67 funcname=['

書架','

書城','

分類','我的'

]8 case1=

9 case2=

1011 version_dict=

1213

14class

template_mixin(object):

15"""

html報告

"""16 html_tmpl = r"""

1718

1929

3031

3233

3435

3637

38客戶端及版本

39通過率

40開始時間

41結束時間

4243

%(table_tr)s

4445

測試詳情 :執行結果

4647

4849

5051

5253

5455

業務模組

56用例總數

57通過數

58狀態

5960

%(table_tr2)s

61%(table_tr3)s

6263

6465

66"""67#

總資料68 table_tmpl_total = """

6970

%(version)s

71%(radio)s

72%(runstarttime)s

73%(runstoptime)s

74"""75#

詳情表頭

76 table_tmpl_module = """

7778

%(name)s

79%(module)s

80%(casetotal)s

81%(passtotal)s

82%(status)s

83"""84#

case資料

85 table_tmpl_case = """

8687

%(name)s

88%(module)s

89%(casetotal)s

90%(passtotal)s

91%(status)s

92"""

9394

9596

if__name__ == '

__main__':

97 table_tr0 = ''

98 table_tr1=""

99 table_tr2=""

100101 numfail = 1

102 numsucc = 9

103 html =template_mixin()

104105

#總表資料

106 table_td = html.table_tmpl_total % dict(version=version_dict['

version

'],radio=version_dict['

radio

'],runstarttime=version_dict['

runstarttime

'],runstoptime = version_dict['

runstoptime'])

107 table_tr0 +=table_td

108109

#詳情資料

110 table_td_module=html.table_tmpl_module % dict(name="",module=case1["

name

"],casetotal=case1["

total

"],passtotal=case1["

passnum

"],status=case1["

status

"],)

111 table_tr1 +=table_td_module

112113

#表頭總數

114 total_str = '

共 %s,通過 %s,失敗 %s

' % (numfail +numsucc, numsucc, numfail)

115116

#case資料

117 table_td_case=html.table_tmpl_case % dict(name="",module=case2["

name

"],casetotal=case2["

total

"],passtotal=case2["

passnum

"],status=case2["

status

"],)

118 table_tr2 +=table_td_case

119120 output=html.html_tmpl % dict(value = total_str,table_tr = table_tr0,table_tr2=table_tr1,table_tr3=table_tr2)

121122

#生成html報告

123 filename='

_testreport.html

'.format(date=time.strftime('

%y%m%d%h%m%s'))

124125

print

(filename)

126#

獲取report的路徑

127 dir= os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),'

report')

128 filename=os.path.join(dir,filename)

129130 with open(filename, 'wb'

) as f:

131 f.write(output.encode('

utf8

'))

view code

生成html靜態頁

方案1 傳入url返回網頁的html url public static string geturltohtml string url get the response stream.system.io.stream respstream wresp.getresponsestream dim re...

生成html靜態頁

方案1 傳入url返回網頁的html url public static string geturltohtml string url get the response stream.system.io.stream respstream wresp.getresponsestream dim re...

生成html靜態頁

方案1 傳入url返回網頁的html url public static string geturltohtml string url get the response stream.system.io.stream respstream wresp.getresponsestream dim re...