@@ -31,6 +31,9 @@ module WebDriver
3131 ( handles - [ driver . window_handle ] ) . each do |handle |
3232 driver . switch_to . window ( handle ) { driver . close }
3333 end
34+ rescue Selenium ::WebDriver ::Error ::WebDriverError
35+ # https://issues.chromium.org/issues/400087471
36+ reset_driver!
3437 end
3538
3639 let ( :new_window ) { driver . window_handles . find { |handle | handle != driver . window_handle } }
@@ -310,25 +313,25 @@ module WebDriver
310313 wait_for_no_alert
311314 end
312315
313- it 'raises when calling #text on a closed alert' do
314- driver . navigate . to url_for ( 'alerts.html' )
315- wait_for_element ( id : 'alert' )
316+ describe 'errors' do
317+ after { |example | reset_driver! ( example : example ) }
316318
317- driver . find_element ( id : 'alert' ) . click
319+ it 'raises when calling #text on a closed alert' do
320+ driver . navigate . to url_for ( 'alerts.html' )
321+ wait_for_element ( id : 'alert' )
318322
319- alert = wait_for_alert
320- alert . accept
323+ driver . find_element ( id : 'alert' ) . click
321324
322- wait_for_no_alert
323- expect { alert . text } . to raise_error ( Selenium ::WebDriver ::Error ::NoSuchAlertError )
324- end
325+ alert = wait_for_alert
326+ alert . accept
325327
326- it 'raises NoAlertOpenError if no alert is present' do
327- expect { driver . switch_to . alert } . to raise_error ( Selenium ::WebDriver ::Error ::NoSuchAlertError )
328- end
328+ wait_for_no_alert
329+ expect { alert . text } . to raise_error ( Selenium ::WebDriver ::Error ::NoSuchAlertError )
330+ end
329331
330- describe 'unhandled alert error' do
331- after { |example | reset_driver! ( example : example ) }
332+ it 'raises NoAlertOpenError if no alert is present' do
333+ expect { driver . switch_to . alert } . to raise_error ( Selenium ::WebDriver ::Error ::NoSuchAlertError )
334+ end
332335
333336 it 'raises an UnexpectedAlertOpenError if an alert has not been dealt with' do
334337 driver . navigate . to url_for ( 'alerts.html' )
0 commit comments