Skip to content

Commit b6e6c7d

Browse files
committed
Fix a bug that prevented some Xvfb processes from ending
1 parent b023adf commit b6e6c7d

File tree

3 files changed

+55
-53
lines changed

3 files changed

+55
-53
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def __initialize_variables(self):
173173
self._chart_first_series = {}
174174
self._chart_series_count = {}
175175
self._tour_steps = {}
176+
self._xvfb_display = None
176177

177178
@classmethod
178179
def main(self, name, file, *args):
@@ -12721,8 +12722,9 @@ def __activate_virtual_display_as_needed(self):
1272112722
try:
1272212723
from sbvirtualdisplay import Display
1272312724

12724-
self.display = Display(visible=0, size=(width, height))
12725-
self.display.start()
12725+
self._xvfb_display = Display(visible=0, size=(width, height))
12726+
self._xvfb_display.start()
12727+
sb_config._virtual_display = self._xvfb_display
1272612728
self.headless_active = True
1272712729
sb_config.headless_active = True
1272812730
except Exception:
@@ -14833,15 +14835,6 @@ def tearDown(self):
1483314835
self.__activate_debug_mode_in_teardown()
1483414836
# (Pytest) Finally close all open browser windows
1483514837
self.__quit_all_drivers()
14836-
if self.headless or self.headless2 or self.xvfb:
14837-
if self.headless_active:
14838-
try:
14839-
self.display.stop()
14840-
except AttributeError:
14841-
pass
14842-
except Exception:
14843-
pass
14844-
self.display = None
1484514838
if self.with_db_reporting:
1484614839
if has_exception:
1484714840
self.__insert_test_result(constants.State.FAILED, True)
@@ -14924,15 +14917,6 @@ def tearDown(self):
1492414917
print(msg)
1492514918
if self.dashboard:
1492614919
self.__process_dashboard(has_exception)
14927-
if self.headless or self.headless2 or self.xvfb:
14928-
if self.headless_active:
14929-
try:
14930-
self.display.stop()
14931-
except AttributeError:
14932-
pass
14933-
except Exception:
14934-
pass
14935-
self.display = None
1493614920
if has_exception:
1493714921
test_id = self.__get_test_id()
1493814922
test_logpath = os.path.join(self.log_path, test_id)
@@ -14987,6 +14971,16 @@ def tearDown(self):
1498714971
# (Nosetests / Behave / Pure Python) Close all open browser windows
1498814972
self.__quit_all_drivers()
1498914973
# Resume tearDown() for all test runners, (Pytest / Nosetests / Behave)
14974+
if hasattr(self, "_xvfb_display") and self._xvfb_display:
14975+
try:
14976+
if hasattr(self._xvfb_display, "stop"):
14977+
self._xvfb_display.stop()
14978+
self._xvfb_display = None
14979+
self.headless_active = False
14980+
except AttributeError:
14981+
pass
14982+
except Exception:
14983+
pass
1499014984
if self.__visual_baseline_copies:
1499114985
sb_config._visual_baseline_copies = True
1499214986
if has_exception:

seleniumbase/plugins/pytest_plugin.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,24 +1825,22 @@ def pytest_runtest_teardown(item):
18251825
except Exception:
18261826
pass
18271827
try:
1828-
if hasattr(self, "xvfb") and self.xvfb:
1829-
if self.headless_active and "--pdb" not in sys_argv:
1830-
if hasattr(self, "display") and self.display:
1831-
self.headless_active = False
1832-
sb_config.headless_active = False
1833-
self.display.stop()
1834-
elif hasattr(self, "headless") and self.headless:
1835-
if self.headless_active and "--pdb" not in sys_argv:
1836-
if hasattr(self, "display") and self.display:
1837-
self.headless_active = False
1838-
sb_config.headless_active = False
1839-
self.display.stop()
1840-
elif hasattr(self, "headless2") and self.headless2:
1841-
if self.headless_active and "--pdb" not in sys_argv:
1842-
if hasattr(self, "display") and self.display:
1843-
self.headless_active = False
1844-
sb_config.headless_active = False
1845-
self.display.stop()
1828+
if (
1829+
hasattr(self, "_xvfb_display")
1830+
and self._xvfb_display
1831+
and hasattr(self._xvfb_display, "stop")
1832+
):
1833+
self.headless_active = False
1834+
sb_config.headless_active = False
1835+
self._xvfb_display.stop()
1836+
self._xvfb_display = None
1837+
if (
1838+
hasattr(sb_config, "_virtual_display")
1839+
and sb_config._virtual_display
1840+
and hasattr(sb_config._virtual_display, "stop")
1841+
):
1842+
sb_config._virtual_display.stop()
1843+
sb_config._virtual_display = None
18461844
except Exception:
18471845
pass
18481846
except Exception:

seleniumbase/plugins/selenium_plugin.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,6 @@ def beforeTest(self, test):
11231123
# (Set --server="127.0.0.1" for localhost Grid)
11241124
if str(self.options.port) == "443":
11251125
test.test.protocol = "https"
1126-
if self.options.xvfb and "linux" not in sys.platform:
1127-
# The Xvfb virtual display server is for Linux OS Only!
1128-
self.options.xvfb = False
11291126
if (
11301127
"linux" in sys.platform
11311128
and not self.options.headed
@@ -1171,6 +1168,9 @@ def beforeTest(self, test):
11711168
if not self.options.headless and not self.options.headless2:
11721169
self.options.headed = True
11731170
test.test.headed = True
1171+
sb_config._virtual_display = None
1172+
sb_config.headless_active = False
1173+
self.headless_active = False
11741174
if (
11751175
self.options.headless
11761176
or self.options.headless2
@@ -1180,8 +1180,9 @@ def beforeTest(self, test):
11801180
# from pyvirtualdisplay import Display # Skip for own lib
11811181
from sbvirtualdisplay import Display
11821182

1183-
self.display = Display(visible=0, size=(1440, 1880))
1184-
self.display.start()
1183+
self._xvfb_display = Display(visible=0, size=(1440, 1880))
1184+
self._xvfb_display.start()
1185+
sb_config._virtual_display = self._xvfb_display
11851186
self.headless_active = True
11861187
sb_config.headless_active = True
11871188
except Exception:
@@ -1213,13 +1214,22 @@ def afterTest(self, test):
12131214
pass
12141215
except Exception:
12151216
pass
1216-
if self.options.headless or self.options.xvfb:
1217-
if self.headless_active:
1218-
try:
1219-
self.headless_active = False
1220-
sb_config.headless_active = False
1221-
self.display.stop()
1222-
except AttributeError:
1223-
pass
1224-
except Exception:
1225-
pass
1217+
try:
1218+
if (
1219+
hasattr(self, "_xvfb_display")
1220+
and self._xvfb_display
1221+
and hasattr(self._xvfb_display, "stop")
1222+
):
1223+
self.headless_active = False
1224+
sb_config.headless_active = False
1225+
self._xvfb_display.stop()
1226+
self._xvfb_display = None
1227+
if (
1228+
hasattr(sb_config, "_virtual_display")
1229+
and sb_config._virtual_display
1230+
and hasattr(sb_config._virtual_display, "stop")
1231+
):
1232+
sb_config._virtual_display.stop()
1233+
sb_config._virtual_display = None
1234+
except Exception:
1235+
pass

0 commit comments

Comments
 (0)