Skip to content

Commit 1d39d6b

Browse files
carlosgcamposlmtierney
authored andcommitted
[py] Fix internal error when an unexpected exception is raised while running window_switching_tests (#4654)
This is happening since the switch to use a global driver instance. The problem is that when a test fails with an exception the pytest_exception_interact() is called, which quits the driver, and then the teardown part of the close_windows fixture tries to close the windows, but window_handles fails because the driver process is no longer running. We can handle URLError exception when getting the window handles and simply return without trying to close the windows.
1 parent 9a6bbe4 commit 1d39d6b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

py/test/selenium/webdriver/common/window_switching_tests.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@
2828
def close_windows(driver):
2929
main_windows_handle = driver.current_window_handle
3030
yield
31-
for handle in driver.window_handles:
31+
try:
32+
from urllib import request as url_request
33+
URLError = url_request.URLError
34+
except ImportError:
35+
import urllib2 as url_request
36+
import urllib2
37+
URLError = urllib2.URLError
38+
39+
try:
40+
window_handles = driver.window_handles
41+
except URLError:
42+
return
43+
for handle in window_handles:
3244
if handle != main_windows_handle:
3345
driver.switch_to.window(handle)
3446
driver.close()

0 commit comments

Comments
 (0)