Skip to content

Commit 7ffd0c9

Browse files
committed
Improve pytest-html reports
1 parent a353c53 commit 7ffd0c9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

seleniumbase/core/style_sheet.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import textwrap
23
from seleniumbase.fixtures import constants
34

45

@@ -116,6 +117,7 @@ def get_report_style():
116117
}
117118
</style>"""
118119
)
120+
style = textwrap.dedent(style)
119121
Saved.report_style = style
120122
return style
121123

@@ -132,6 +134,7 @@ def get_bt_backdrop_style():
132134
box-shadow: 0 0 0 88422px rgba(0, 0, 0, 0.42);
133135
pointer-events: auto !important;
134136
}"""
137+
bt_backdrop_style = textwrap.dedent(bt_backdrop_style)
135138
Saved.bt_backdrop_style = bt_backdrop_style
136139
return bt_backdrop_style
137140

@@ -150,6 +153,7 @@ def get_dt_backdrop_style():
150153
button.driver-prev-btn.driver-disabled {
151154
visibility: hidden;
152155
}"""
156+
dt_backdrop_style = textwrap.dedent(dt_backdrop_style)
153157
Saved.dt_backdrop_style = dt_backdrop_style
154158
return dt_backdrop_style
155159

@@ -167,6 +171,7 @@ def get_messenger_style():
167171
box-shadow: 2px 2px 9px 4px rgba(32, 142, 120, 0.28),
168172
2px 2px 9px 4px rgba(200, 240, 80, 0.34) !important;
169173
}""" % font_family
174+
messenger_style = textwrap.dedent(messenger_style)
170175
Saved.messenger_style = messenger_style
171176
return messenger_style
172177

@@ -181,6 +186,7 @@ def get_sh_style_test():
181186
scrollTo: true
182187
}
183188
});"""
189+
sh_style_test = textwrap.dedent(sh_style_test)
184190
Saved.sh_style_test = sh_style_test
185191
return sh_style_test
186192

@@ -193,6 +199,7 @@ def get_hops_backdrop_style():
193199
.hopscotch-bubble-container {
194200
font-size: 110%;
195201
}"""
202+
hops_backdrop_style = textwrap.dedent(hops_backdrop_style)
196203
Saved.hops_backdrop_style = hops_backdrop_style
197204
return hops_backdrop_style
198205

@@ -227,6 +234,7 @@ def get_introjs_style():
227234
box-sizing: content-box;
228235
position: absolute;
229236
}"""
237+
introjs_style = textwrap.dedent(introjs_style)
230238
Saved.introjs_style = introjs_style
231239
return introjs_style
232240

@@ -261,6 +269,7 @@ def get_sh_backdrop_style():
261269
body.shepherd-active {
262270
pointer-events: none !important;
263271
}"""
272+
sh_backdrop_style = textwrap.dedent(sh_backdrop_style)
264273
Saved.sh_backdrop_style = sh_backdrop_style
265274
return sh_backdrop_style
266275

@@ -387,5 +396,6 @@ def get_pytest_style():
387396
.desc.active .sort-icon {
388397
border-top: 8px solid #999;
389398
}"""
399+
pytest_style = textwrap.dedent(pytest_style)
390400
Saved.pytest_style = pytest_style
391401
return pytest_style

seleniumbase/plugins/pytest_plugin.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,20 @@ def _perform_pytest_unconfigure_(config):
22092209
f.write(the_html_r) # Finalize the HTML report
22102210
with open(html_report_path_copy, "w", encoding="utf-8") as f:
22112211
f.write(the_html_r) # Finalize the HTML report
2212+
assets_style = "./assets/style.css"
2213+
if os.path.exists(assets_style):
2214+
html_style = None
2215+
with open(assets_style, "r", encoding="utf-8") as f:
2216+
html_style = f.read()
2217+
if html_style:
2218+
html_style = html_style.replace("top: -50px;", "top: 2px;")
2219+
html_style = html_style.replace("+ 50px)", "+ 40px)")
2220+
html_style = html_style.replace("ht: 240px;", "ht: 228px;")
2221+
html_style = html_style.replace(
2222+
"- 80px);", "- 80px);\n margin-bottom: -42px;"
2223+
)
2224+
with open(assets_style, "w", encoding="utf-8") as f:
2225+
f.write(html_style)
22122226
# Done with "pytest_unconfigure" unless using the Dashboard
22132227
return
22142228
stamp = ""
@@ -2290,6 +2304,20 @@ def _perform_pytest_unconfigure_(config):
22902304
)
22912305
with open(dashboard_path, "w", encoding="utf-8") as f:
22922306
f.write(the_html_d) # Finalize the dashboard
2307+
assets_style = "./assets/style.css"
2308+
if os.path.exists(assets_style):
2309+
html_style = None
2310+
with open(assets_style, "r", encoding="utf-8") as f:
2311+
html_style = f.read()
2312+
if html_style:
2313+
html_style = html_style.replace("top: -50px;", "top: 2px;")
2314+
html_style = html_style.replace("+ 50px)", "+ 40px)")
2315+
html_style = html_style.replace("ht: 240px;", "ht: 228px;")
2316+
html_style = html_style.replace(
2317+
"- 80px);", "- 80px);\n margin-bottom: -42px;"
2318+
)
2319+
with open(assets_style, "w", encoding="utf-8") as f:
2320+
f.write(html_style)
22932321
# Part 2: Appending a pytest html report with dashboard data
22942322
html_report_path = None
22952323
if sb_config._html_report_name:

0 commit comments

Comments
 (0)