Skip to content

Commit c009695

Browse files
authored
Ensure we delete a session when closing the last window (#53735)
Previously, we just set `session.session_id` to `None`; this is valid if the browser has (correctly) deleted the session, but is very problematic if it has not, as it means we no longer have the `session_id` of the currently active session, and thus we can neither use that session nor delete the session. This copies what we do in the delete session tests, and both checks that the session has been deleted, and then cleanly ends the session. This should get the majority of WebDriver tests passing again on STP, where everything after this test fails with: webdriver.error.SessionNotCreatedException: session not created (500): Could not create a session: The Safari instance is already paired with another WebDriver session.
1 parent 3cd817f commit c009695

File tree

1 file changed

+9
-2
lines changed
  • webdriver/tests/classic/close_window

1 file changed

+9
-2
lines changed

webdriver/tests/classic/close_window/close.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,15 @@ def test_close_last_browsing_context(session):
7373

7474
assert_success(response, [])
7575

76-
# With no more open top-level browsing contexts, the session is closed.
77-
session.session_id = None
76+
try:
77+
# The session should've been deleted by closing the last context.
78+
with pytest.raises(error.InvalidSessionIdException):
79+
session.handles
80+
81+
finally:
82+
# Need an explicit call to session.end() to notify the test harness
83+
# that a new session needs to be created for subsequent tests.
84+
session.end()
7885

7986

8087
def test_element_usage_after_closing_browsing_context(session, inline):

0 commit comments

Comments
 (0)