Skip to content

Commit 8924f0b

Browse files
committed
Make improvements to the SeleniumBase Dashboard
1 parent e39bddf commit 8924f0b

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9773,6 +9773,8 @@ def __get_test_id(self):
97739773

97749774
def __get_test_id_2(self):
97759775
""" The id for SeleniumBase Dashboard entries. """
9776+
if "PYTEST_CURRENT_TEST" in os.environ:
9777+
return os.environ["PYTEST_CURRENT_TEST"].split(" ")[0]
97769778
test_id = "%s.%s.%s" % (
97779779
self.__class__.__module__.split(".")[-1],
97789780
self.__class__.__name__,
@@ -9786,6 +9788,8 @@ def __get_test_id_2(self):
97869788

97879789
def __get_display_id(self):
97889790
""" The id for running a test from pytest. (Displayed on Dashboard) """
9791+
if "PYTEST_CURRENT_TEST" in os.environ:
9792+
return os.environ["PYTEST_CURRENT_TEST"].split(" ")[0]
97899793
test_id = "%s.py::%s::%s" % (
97909794
self.__class__.__module__.replace(".", "/"),
97919795
self.__class__.__name__,
@@ -10139,7 +10143,9 @@ def __process_dashboard(self, has_exception, init=False):
1013910143
out_file = codecs.open(file_path, "w+", encoding="utf-8")
1014010144
out_file.writelines(the_html)
1014110145
out_file.close()
10146+
sb_config._dash_html = the_html
1014210147
if self._multithreaded:
10148+
sb_config._dash_html_for_multithreading = the_html
1014310149
d_stats = (num_passed, num_failed, num_skipped, num_untested)
1014410150
_results = sb_config._results
1014510151
_display_id = sb_config._display_id

seleniumbase/plugins/pytest_plugin.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import colorama
55
import os
66
import pytest
7-
import re
87
import sys
98
import time
109
from seleniumbase import config as sb_config
@@ -967,6 +966,7 @@ def pytest_configure(config):
967966
sb_config.item_count_skipped = 0
968967
sb_config.item_count_untested = 0
969968
sb_config.is_pytest = True
969+
sb_config.pytest_config = config
970970
sb_config.browser = config.getoption("browser")
971971
if sb_config._browser_shortcut:
972972
sb_config.browser = sb_config._browser_shortcut
@@ -1129,10 +1129,16 @@ def pytest_sessionstart(session):
11291129

11301130

11311131
def _get_test_ids_(the_item):
1132-
test_id = the_item.nodeid.split("/")[-1]
1132+
test_id = the_item.nodeid
11331133
if not test_id:
11341134
test_id = "unidentified_TestCase"
1135-
test_id = test_id.replace(" ", "_")
1135+
display_id = test_id
1136+
r"""
1137+
# Due to changes in SeleniumBase 1.66.0, we're now using the
1138+
# item's original nodeid for both the test_id and display_id.
1139+
# (This only impacts tests using The Dashboard.)
1140+
# If there are any issues, we'll revert back to the old code.
1141+
test_id = the_item.nodeid.split("/")[-1].replace(" ", "_")
11361142
if "[" in test_id:
11371143
test_id_intro = test_id.split("[")[0]
11381144
parameter = test_id.split("[")[1]
@@ -1141,12 +1147,13 @@ def _get_test_ids_(the_item):
11411147
display_id = test_id
11421148
test_id = test_id.replace("/", ".").replace("\\", ".")
11431149
test_id = test_id.replace("::", ".").replace(".py", "")
1150+
"""
11441151
return test_id, display_id
11451152

11461153

11471154
def _create_dashboard_assets_():
11481155
import codecs
1149-
from seleniumbase.core.js_snippets import live_js
1156+
from seleniumbase.js_code.live_js import live_js
11501157
from seleniumbase.core.style_sheet import pytest_style
11511158

11521159
abs_path = os.path.abspath(".")
@@ -1292,6 +1299,14 @@ def pytest_terminal_summary(terminalreporter):
12921299

12931300
def pytest_unconfigure():
12941301
""" This runs after all tests have completed with pytest. """
1302+
if (
1303+
hasattr(sb_config, "_dash_html_for_multithreading")
1304+
and sb_config._multithreaded
1305+
):
1306+
abs_path = os.path.abspath(".")
1307+
dashboard_path = os.path.join(abs_path, "dashboard.html")
1308+
with open(dashboard_path, "w", encoding="utf-8") as f:
1309+
f.write(sb_config._dash_html)
12951310
proxy_helper.remove_proxy_zip_if_present()
12961311
if hasattr(sb_config, "reuse_session") and sb_config.reuse_session:
12971312
# Close the shared browser session
@@ -1336,7 +1351,7 @@ def pytest_unconfigure():
13361351
swap_with = "" # Stop refreshing the page after the run is done
13371352
find_it_2 = "Awaiting results... (Refresh the page for updates)"
13381353
swap_with_2 = (
1339-
"Test Run ENDED: Some results UNREPORTED due to skipped tearDown!"
1354+
"Test Run ENDED: Some results UNREPORTED due to skipped tearDown()"
13401355
)
13411356
find_it_3 = '<td class="col-result">Untested</td>'
13421357
swap_with_3 = '<td class="col-result">Unreported</td>'
@@ -1525,14 +1540,20 @@ def pytest_runtest_makereport(item, call):
15251540
test_id = item.nodeid
15261541
if not test_id:
15271542
test_id = "unidentified_TestCase"
1528-
test_id = test_id.replace(" ", "_")
1543+
r"""
1544+
# Due to changes in SeleniumBase 1.66.0, we're now using the
1545+
# item's original nodeid for both the test_id and display_id.
1546+
# (This only impacts tests using The Dashboard.)
1547+
# If there are any issues, we'll revert back to the old code.
1548+
test_id = test_id.split("/")[-1].replace(" ", "_")
15291549
if "[" in test_id:
15301550
test_id_intro = test_id.split("[")[0]
15311551
parameter = test_id.split("[")[1]
15321552
parameter = re.sub(re.compile(r"\W"), "", parameter)
15331553
test_id = test_id_intro + "__" + parameter
15341554
test_id = test_id.replace("/", ".").replace("\\", ".")
15351555
test_id = test_id.replace("::", ".").replace(".py", "")
1556+
"""
15361557
sb_node._sb_test_identifier = test_id
15371558
if sb_node._needs_tearDown:
15381559
sb_node.tearDown()

0 commit comments

Comments
 (0)