Principle:Teamcapybara Capybara Session Cleanup
| Knowledge Sources | |
|---|---|
| Domains | Testing, Session_Management |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A test isolation pattern that resets browser sessions and driver state between test executions to prevent cross-test contamination.
Description
Session Cleanup ensures that each test starts with a clean browser state. Between tests, all sessions in the session pool are reset (cookies cleared, page navigated to blank), and the driver selection is reverted to the default. This prevents one test's cookies, page state, or driver choice from affecting subsequent tests.
The cleanup handles two distinct concerns:
- Session reset — Each session's cookies, page content, and driver state are cleared
- Driver reset — The current driver override is cleared, falling back to the configured default
Usage
This principle is applied automatically by Capybara's RSpec after hook. It can also be called manually between test blocks or in custom test framework integrations.
Theoretical Basis
# Abstract cleanup flow (not actual code)
for each session in session_pool (reverse order):
session.reset! # clear cookies, navigate to blank page, reset driver state
wait_for_pending_server_requests
raise_any_server_errors
current_driver = nil # fall back to default_driver