Skip to content

Commit 91c7646

Browse files
committed
Check for service process before driver.quit() on Windows
1 parent 2514147 commit 91c7646

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def test_anything(self):
6868
logging.getLogger("urllib3").setLevel(logging.ERROR)
6969
urllib3.disable_warnings()
7070
LOGGER.setLevel(logging.WARNING)
71+
is_windows = False
72+
if sys.platform in ["win32", "win64", "x64"]:
73+
is_windows = True
7174
python3 = True
7275
if sys.version_info[0] < 3:
7376
python3 = False
@@ -9979,7 +9982,8 @@ def quit_extra_driver(self, driver=None):
99799982
"Use this method only if get_new_driver() has been called."
99809983
)
99819984
try:
9982-
driver.quit()
9985+
if not is_windows or driver.service.process:
9986+
driver.quit()
99839987
except AttributeError:
99849988
pass
99859989
except Exception:
@@ -11666,7 +11670,8 @@ def __quit_all_drivers(self):
1166611670
self._drivers_list.reverse() # Last In, First Out
1166711671
for driver in self._drivers_list:
1166811672
try:
11669-
driver.quit()
11673+
if not is_windows or driver.service.process:
11674+
driver.quit()
1167011675
except AttributeError:
1167111676
pass
1167211677
except Exception:

seleniumbase/plugins/pytest_plugin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from seleniumbase.config import settings
1111
from seleniumbase.fixtures import constants
1212

13+
is_windows = False
14+
if sys.platform in ["win32", "win64", "x64"]:
15+
is_windows = True
1316
pytest_plugins = ["pytester"] # Adds the "testdir" fixture
1417

1518

@@ -1349,7 +1352,8 @@ def pytest_runtest_teardown(item):
13491352
and self.driver
13501353
and "--pdb" not in sys.argv
13511354
):
1352-
self.driver.quit()
1355+
if not is_windows or self.driver.service.process:
1356+
self.driver.quit()
13531357
except Exception:
13541358
pass
13551359
try:
@@ -1402,7 +1406,8 @@ def _perform_pytest_unconfigure_():
14021406
# Close the shared browser session
14031407
if sb_config.shared_driver:
14041408
try:
1405-
sb_config.shared_driver.quit()
1409+
if not is_windows or sb_config.shared_driver.service.process:
1410+
sb_config.shared_driver.quit()
14061411
except AttributeError:
14071412
pass
14081413
except Exception:

seleniumbase/plugins/selenium_plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from seleniumbase.core import proxy_helper
99
from seleniumbase.fixtures import constants
1010

11+
is_windows = False
12+
if sys.platform in ["win32", "win64", "x64"]:
13+
is_windows = True
14+
1115

1216
class SeleniumBrowser(Plugin):
1317
"""
@@ -744,7 +748,8 @@ def finalize(self, result):
744748
def afterTest(self, test):
745749
try:
746750
# If the browser window is still open, close it now.
747-
self.driver.quit()
751+
if not is_windows or self.driver.service.process:
752+
self.driver.quit()
748753
except AttributeError:
749754
pass
750755
except Exception:

0 commit comments

Comments
 (0)