Skip to content

Commit 10a92ca

Browse files
committed
Fix sessions not working after error or unload alert popping up
1 parent 1ddb041 commit 10a92ca

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/support/capybara.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,17 @@ def teardown
141141
super
142142

143143
# Clear the session and logout after each test.
144-
::Capybara.reset_sessions!
144+
begin
145+
::Capybara.reset_sessions!
146+
rescue
147+
# Resetting may fail since it navigates away from the page, which may
148+
# trigger an extra `onbeforeunload` alert warning. Since this is not
149+
# automatically handled (due to `unhandled_prompt_behavior`), trigger
150+
# the internal mechanism to dismiss these unload alerts, and then try
151+
# resetting again.
152+
::Capybara.current_session.driver.send(:accept_unhandled_reset_alert)
153+
retry
154+
end
145155

146156
# Ensure the default driver is used again for future tests (for any
147157
# tests that may have changed the driver).

0 commit comments

Comments
 (0)