Principle:Teamcapybara Capybara Driver Selection Configuration
| Knowledge Sources | |
|---|---|
| Domains | Testing, Configuration |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A configuration pattern for selecting which browser driver handles test interactions, supporting both persistent defaults and per-test overrides.
Description
Driver Selection Configuration is the mechanism by which a test framework chooses between different browser automation backends (e.g., RackTest for fast headless HTTP, Selenium for JavaScript-capable browser tests). The pattern supports three levels of configuration:
- default_driver — The persistent driver used when no override is set (defaults to :rack_test)
- javascript_driver — The driver automatically activated when a test is tagged with js: true (defaults to :selenium)
- current_driver — A per-test override that takes precedence, reset after each test
This layered approach allows fast non-JS tests to run with RackTest while JS-dependent tests automatically switch to a browser-based driver.
Usage
Use this principle at application configuration time to set which drivers are used by default and for JavaScript tests. Set default_driver when you want all tests to use a specific driver, and javascript_driver when only JS-tagged tests need a browser.
Theoretical Basis
The resolution order is:
# Abstract resolution (not actual code)
effective_driver = current_driver || default_driver
# Where current_driver is set per-test and cleared after each test
# javascript_driver is applied via before hooks when js: true