Skip to content

Commit 3e7f5e4

Browse files
committed
Make sure the Dashboard refreshes properly on update
1 parent 01ce846 commit 3e7f5e4

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

seleniumbase/plugins/pytest_plugin.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -766,49 +766,57 @@ def pytest_unconfigure():
766766
find_it = constants.Dashboard.META_REFRESH_HTML
767767
swap_with = '' # Stop refreshing the page after the run is done
768768
try:
769-
# Part 1: Finalizing the dashboard / integrating html report
770-
time.sleep(0.3) # Add time for "livejs" to detect changes
771769
abs_path = os.path.abspath('.')
772770
dashboard_path = os.path.join(abs_path, "dashboard.html")
771+
# Part 1: Finalizing the dashboard / integrating html report
773772
if os.path.exists(dashboard_path):
773+
the_html_d = None
774774
with open(dashboard_path, 'r', encoding='utf-8') as f:
775-
the_html = f.read()
775+
the_html_d = f.read()
776776
# If the test run doesn't complete by itself, stop refresh
777-
the_html = the_html.replace(find_it, swap_with)
778-
the_html += stamp
777+
the_html_d = the_html_d.replace(find_it, swap_with)
778+
the_html_d += stamp
779779
if sb_config._dash_is_html_report and (
780780
sb_config._saved_dashboard_pie):
781-
the_html = the_html.replace(
781+
the_html_d = the_html_d.replace(
782782
"<h1>dashboard.html</h1>",
783783
sb_config._saved_dashboard_pie)
784-
the_html = the_html.replace(
784+
the_html_d = the_html_d.replace(
785785
"</head>", '</head><link rel="shortcut icon" '
786786
'href="https://seleniumbase.io/img/dash_pie_2.png">')
787787
if sb_config._dash_final_summary:
788-
the_html += sb_config._dash_final_summary
789-
time.sleep(0.25)
788+
the_html_d += sb_config._dash_final_summary
789+
with open(dashboard_path, "w", encoding='utf-8') as f:
790+
f.write(the_html_d) # Finalize the dashboard
791+
time.sleep(0.5) # Add time for "livejs" to detect changes
792+
the_html_d = the_html_d.replace(
793+
"</head>", "</head><!-- Dashboard Report Done -->")
790794
with open(dashboard_path, "w", encoding='utf-8') as f:
791-
f.write(the_html)
792-
# Part 2: Appending a pytest html report with dashboard data
793-
html_report_path = os.path.join(
794-
abs_path, sb_config._html_report_name)
795-
if sb_config._using_html_report and (
796-
os.path.exists(html_report_path) and
797-
not sb_config._dash_is_html_report):
798-
# Add the dashboard pie to the pytest html report
799-
with open(html_report_path, 'r', encoding='utf-8') as f:
800-
the_html = f.read()
801-
if sb_config._saved_dashboard_pie:
802-
the_html = the_html.replace(
803-
"<h1>%s</h1>" % sb_config._html_report_name,
804-
sb_config._saved_dashboard_pie)
805-
the_html = the_html.replace(
806-
"</head>", '</head><link rel="shortcut icon" '
807-
'href="https://seleniumbase.io/img/dash_pie_2.png">')
808-
if sb_config._dash_final_summary:
809-
the_html += sb_config._dash_final_summary
810-
with open(html_report_path, "w", encoding='utf-8') as f:
811-
f.write(the_html)
795+
f.write(the_html_d) # Finalize the dashboard
796+
# Part 2: Appending a pytest html report with dashboard data
797+
html_report_path = None
798+
if sb_config._html_report_name:
799+
html_report_path = os.path.join(
800+
abs_path, sb_config._html_report_name)
801+
if sb_config._using_html_report and html_report_path and (
802+
os.path.exists(html_report_path) and
803+
not sb_config._dash_is_html_report):
804+
# Add the dashboard pie to the pytest html report
805+
the_html_r = None
806+
with open(html_report_path, 'r', encoding='utf-8') as f:
807+
the_html_r = f.read()
808+
if sb_config._saved_dashboard_pie:
809+
the_html_r = the_html_r.replace(
810+
"<h1>%s</h1>" % sb_config._html_report_name,
811+
sb_config._saved_dashboard_pie)
812+
the_html_r = the_html_r.replace(
813+
"</head>", '</head><link rel="shortcut icon" '
814+
'href='
815+
'"https://seleniumbase.io/img/dash_pie_2.png">')
816+
if sb_config._dash_final_summary:
817+
the_html_r += sb_config._dash_final_summary
818+
with open(html_report_path, "w", encoding='utf-8') as f:
819+
f.write(the_html_r) # Finalize the HTML report
812820
except Exception:
813821
pass
814822

0 commit comments

Comments
 (0)