当前位置: 首页 > 工具软件 > PyH > 使用案例 >

python生成精美html文件_<1>Python生成高质量Html文件:Pyh模块+Bootstrap框架

上官高畅
2023-12-01

1 #!/usr/bin/env python

2 #-*- coding:utf-8 -*-

3

4 from pyh import *

5

6 page = PyH('接口测试报告')                   #第一步:需要先生成含标题的HTML模板7 page.addCSS('https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css')  #第二步:需要加载我们要使用的Bootstrap模板css文件,需要的话还可以加载js8 Container = page << body(id='Body', cl='bg-warning') << div(id="container",cl="container") #第三步:通过移位符“<

10 #报告标题 start

11 Headrow = Container << div(id="Headrow", cl="row")12 Headrow << h1(id="HeadH1",align="center") << strong("API_AutoTest_Report",id="HeadTxt") + small("Sonny.zhang", id="author")13 Headrow <

15

16 #数据统计 start

17 Totalrow = Container << div(id="Totalrow", cl="Totalrow") << div(cl="jumbotron")18 #--测试使用时间,测试用例总数--

19 test_time_txt = ["测试总耗时:", "0:00:04.307585"]20 case_num = ["用例总数:", "7"]21 UTimerow = Totalrow << div(id="UTimerow", cl="row")22 UTimerow << div(cl="col-xs-12 col-md-6") << p(role="presentation") << span(test_time_txt[0]) << span(test_time_txt[1], cl="label label-default")23 UTimerow << div(cl="col-xs-12 col-md-6") << p(role="presentation") << span(case_num[0]) << span(case_num[1],cl="label label-primary")24 #--用例失败成功统计--

25 Num1_txt = ["成功用例数(Pass):", "3"]26 Num2_txt = ["失败用例数(Fail):", "2"]27 Num3_txt = ["出错用例数(Error):", "2"]28 Num4_txt = ["未执行用例数(Block):", "1"]29 Amountrow = Totalrow << div(id="Amountrow", cl="row")30 Num1 = Amountrow << div(id="Num1", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num1_txt[0]) << span(Num1_txt[1], cl="label label-success")31 Num2 = Amountrow << div(id="Num2", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num2_txt[0]) << span(Num2_txt[1], cl="label label-danger")32 Num3 = Amountrow << div(id="Num3", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num3_txt[0]) << span(Num3_txt[1], cl="label label-warning")33 Num4 = Amountrow << div(id="Num4", cl="col-xs-12 col-md-3") << p(role="presentation") << span() << small(Num4_txt[0]) << span(Num4_txt[1], cl="label label-default")34 #数据统计 end

35

36 #测试计划 start

37 Plans = Container << div(id="plans", cl="row")38 #--栏目标题--

39 plans_title = "测试用例摘要"

40 PlansTitle = Plans << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << strong() << center(plans_title, cl="text-uppercase")41

42 #--一个测试计划-- start

43 Plan1 = Plans << div(id="plan1", cl="col-xs-12 col-md-12") << table(cl="table table-striped")44 #---一个标题--

45 plan1_title = "测试计划【项目名称:APItest, 计划名称:user_operation】"

46 Plan1 << center() <

48 #表头

49 thead1 = ["ID", "执行编号", "用例ID", "用例外部ID", "用例名称", "用例套件", "执行结果", "运行时间"]50 Thead1 = Plan1 <

53 tbody1 = ["151", "20180804110924", "1079", "APItest-1", "获取token", "获取token", "Pass", "2018-08-04 11:09:24"]54 Error = "Error"

55 Tbody1 = Plan1 <

59 #测试计划 end

60

61 #测试用例 start

62 Cases = Container << div(cl="row")63 #--栏目标题--

64 cases_title = "用例执行明细"

65 CasesTitle = Cases << div(cl="panel panel-primary") << div(cl="panel-heading") << strong(center(cases_title, cl="text-uppercase"))66 #--一个测试用例-- start

67 Case1 = Cases << div(cl="col-xs-12 col-md-12") << table(cl="table table-striped")68 #---一个标题--

69 Case1_title = "测试计划【项目名称:APItest, 计划名称:user_operation】"

70 Case1 << center() <

72 #表头

73 thead1 = ["ID", "执行编号", "用例ID", "用例外部ID", "用例名称", "用例套件", "执行结果", "运行时间"]74 Case1Thead1 = Case1 <

77 tbody1 = ["151", "20180804110924", "1079", "APItest-1", "获取token", "获取token", "Pass", "2018-08-04 11:09:24"]78 Error = "Error"

79 Case1Tbody1 = Case1 <

83 #测试计划 end

84

85 page.printOut('Pyh_Template.html')

 类似资料: