-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoira-report.py
executable file
·140 lines (115 loc) · 4.67 KB
/
oira-report.py
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"""Plucks out the most important details from the Robot reports for OiRA.
This parses the robot output.xml and produces an HTML file called oira-
report.html
"""
from lxml import etree
from lxml import html
from lxml.html import builder as E
# A plain template with Bootstrap
report = E.HTML(
E.HEAD(
E.LINK(
href=(
"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/"
"bootstrap-combined.min.css"
),
rel="stylesheet",
),
E.TITLE("OiRA Testing Report"),
E.META(name="viewport", content="width=device-width, initial-scale=1.0"),
),
E.BODY(
E.DIV(
E.CLASS("container"),
E.DIV(E.CLASS("page-header"), E.H1("OiRA Testing Report")),
id="content-area",
)
),
)
def format_msg(msg, status):
if msg.text is not None:
if "password" in msg.text:
"""Strip out the test password, just in case the report gets sent
around."""
return E.P("Entering password")
if status == "FAIL":
msg_html = html.fromstring(msg.text)
if msg_html.xpath(".//a") != []:
href = msg_html.xpath(".//a")[0].get("href")
return E.UL(
E.CLASS("thumbnails"),
E.LI(
E.CLASS("span4"),
E.A(E.CLASS("thumbnail"), E.IMG(src=href), href=href),
),
)
else:
return E.P(msg.text)
else:
return E.P(msg.text)
content_area = report.get_element_by_id("content-area")
def process_robot_output(robot_output):
root = etree.parse(robot_output).getroot() # nosec # TODO
print("one time")
for suite in root.xpath("//suite[@source]"):
suite_id = suite.get("id", "")
suite_container = E.DIV(E.CLASS("suite span12"), id=suite_id)
suite_container.append(E.H3(E.CLASS("span12"), suite.get("name", "")))
tests = suite.xpath(".//test")
for i, test in enumerate(tests):
test_id = "{}".format(test.get("id", ""))
test_container = E.DIV(E.CLASS("span6"))
test_name = test.get("name", "")
test_container.append(E.H4(test_name))
doc = "".join(
[doc.text for doc in test.xpath("./doc") if doc.text is not None]
)
test_container.append(E.P(doc))
status_tags = test.xpath("./status")
status = ""
if status_tags != []:
status = status_tags[0].get("status")
if status == "PASS":
btn_class = "btn-success"
text_class = "text-success"
elif status == "FAIL":
btn_class = "btn-danger"
text_class = "text-error"
btn_id = test_id + "-btn"
test_container.append(
E.BUTTON(status, E.CLASS("btn " + btn_class), type="button", id=btn_id)
)
btn = test_container.get_element_by_id(btn_id)
btn.set("data-target", "#" + test_id)
btn.set("data-toggle", "collapse")
messages = E.DIV(E.CLASS("collapse " + text_class), id=test_id)
for kw in test.xpath("./kw"):
for msg in kw.xpath(".//msg"):
messages.append(format_msg(msg, status=status))
if kw.get("name") == "Selenium2Library.Wait Until Page Contains":
text_check = ["text" in doc.text for doc in kw.xpath(".//doc")]
if text_check:
text_match = " ".join([arg.text for arg in kw.xpath(".//arg")])
messages.append(E.P("Checking the page contains: " + text_match))
test_container.append(messages)
# Two columns per row
if i % 2 == 0 or i == len(tests):
row = E.DIV(E.CLASS("row"), test_container)
suite_container.append(row)
else:
row.append(test_container)
content_area.append(E.DIV(E.CLASS("row"), suite_container))
# ScrollSpy might be nice
# report.body.set("data-spy","scroll")
# report.body.set("data-target", ".suite")
report.append(E.SCRIPT(src="http://code.jquery.com/jquery-1.9.1.min.js"))
report.append(
E.SCRIPT(
src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js" # noqa: E501
)
)
if __name__ == "__main__":
robot_output = open("output.xml")
process_robot_output(robot_output)
report_output = open("oira-report.html", "w")
report_output.write(html.tostring(report))