Repository navigation
Expand file tree
/
Copy pathcheckRobotFrameworkHtmlReport.py
More file actions
executable file
·122 lines (100 loc) · 3.61 KB
/
Copy pathcheckRobotFrameworkHtmlReport.py
File metadata and controls
executable file
·122 lines (100 loc) · 3.61 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import argparse
import os
import re
import sys
from common.python.html_builder import (
generate_header,
generate_footer,
generate_chapter,
generate_button_header,
generate_button_footer,
generate_image_table_header,
generate_image_table_footer,
generate_image_table_row,
generate_image_table_separator,
generate_list_header,
generate_list_footer,
generate_list_row,
generate_list_sub_header,
generate_list_sub_footer,
generate_list_sub_row,
)
from robot.api import ExecutionResult
REPORT_NAME = 'test_results_robot_framework.html'
class HtmlReport():
def __init__(self):
pass
def generate(self, args):
cwd = os.getcwd()
status = True
with open(os.path.join(cwd, REPORT_NAME), 'w') as wfile:
wfile.write(generate_header(args))
(status, testSummary) = self.testSummary('Robot Framework Tests')
wfile.write(testSummary)
wfile.write(generate_footer())
if status:
sys.exit(0)
else:
sys.exit(-1)
def testSummary(self, testName):
cwd = os.getcwd()
if not os.path.isdir(cwd + '/archives/'):
return ''
testDetails = ""
path = os.path.join(cwd, "archives")
path = os.path.join(path, "output.xml")
result = ExecutionResult(path)
stats = result.statistics
globalStatus = False
if stats.total.passed == stats.total.total:
statusDescription = f'All {stats.total.passed} robot tests passed!'
globalStatus = True
else:
statusDescription = f'Only {stats.total.passed} out of {stats.total.total} robot tests passed'
testDetails += generate_chapter('Robot Framework Test Summary', statusDescription, globalStatus)
testDetails += generate_list_row(f'More details can be found in the <a href="archives/log.html"> robot framework log </a>', 'info-sign')
testDetails += generate_list_row(f'NGAP Tester Logs on private CI server at `oaicicd@selfix:/opt/ngap-tester-logs/cn5g_fed-{args.job_name}-{args.job_id}.zip`', 'info-sign')
return (globalStatus, testDetails)
def _parse_args() -> argparse.Namespace:
"""Parse the command line args
Returns:
argparse.Namespace: the created parser
"""
example_text = '''example:
./ci-scripts/checkNgapTesterHtmlReport.py --help
./ci-scripts/checkNgapTesterHtmlReport.py --job_name NameOfPipeline --job_id BuildNumber --job_url BuildURL'''
parser = argparse.ArgumentParser(description='OAI 5G CORE NETWORK NGAP-Tester HTML report',
epilog=example_text,
formatter_class=argparse.RawDescriptionHelpFormatter)
# Job Name
parser.add_argument(
'--job_name', '-n',
action='store',
help='Pipeline is called JOB_NAME',
)
# Job Build Id
parser.add_argument(
'--job_id', '-id',
action='store',
help='Build # JOB_ID',
)
# Job URL
parser.add_argument(
'--job_url', '-u',
action='store',
help='Pipeline provides an URL for this run',
)
return parser.parse_args()
#--------------------------------------------------------------------------------------------------------
#
# Start of main
#
#--------------------------------------------------------------------------------------------------------
if __name__ == '__main__':
# Parse the arguments
args = _parse_args()
# Generate report
HTML = HtmlReport()
HTML.generate(args)