Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Teamcapybara Capybara Session Cleanup

From Leeroopedia
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

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment