Implementation:Teamcapybara Capybara Spec Node
| Knowledge Sources | |
|---|---|
| Domains | Testing, Test_Specification |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
This shared test suite validates the Capybara::Node::Element API, covering the full range of node interaction and inspection methods used by driver implementations.
Description
The file defines shared RSpec examples via Capybara::SpecHelper.spec 'node' that exercise all public methods on Node::Element objects. It is designed to be executed against any Capybara driver to verify correct behavior of text and value retrieval, attribute access, element visibility, style computation, click interactions (single, double, right-click with offset and modifier support), drag-and-drop (including HTML5, Dragula, and jsTree), file dropping, hovering, scrolling, send_keys, script execution (execute_script and evaluate_script), shadow DOM traversal, element reloading, equality checks, and server error synchronization. Many test scenarios are gated behind requires metadata tags (e.g., :js, :css, :drag, :hover, :send_keys, :shadow_dom) so that drivers only run the tests they support.
Usage
Driver test suites include this shared spec by calling Capybara::SpecHelper.run_specs with their session object. For example, the Rack Test and Selenium driver specs both invoke these shared examples, skipping any scenarios that require capabilities the driver does not support. This ensures a consistent behavioral contract across all Capybara drivers.
Code Reference
Source Location
- Repository: Teamcapybara_Capybara
- File: lib/capybara/spec/session/node_spec.rb
- Lines: 1-1416
Signature
Capybara::SpecHelper.spec 'node' do
before do
@session.visit('/with_html')
end
it 'should act like a session object' do
# ...
end
describe '#text' do ... end
describe '#[]' do ... end
describe '#style', requires: [:css] do ... end
describe '#value' do ... end
describe '#set' do ... end
describe '#tag_name' do ... end
describe '#disabled?' do ... end
describe '#visible?' do ... end
describe '#checked?' do ... end
describe '#selected?' do ... end
describe '#==' do ... end
describe '#path' do ... end
describe '#trigger', requires: %i[js trigger] do ... end
describe '#drag_to', requires: %i[js drag] do ... end
describe '#drop', requires: %i[js drop] do ... end
describe '#hover', requires: [:hover] do ... end
describe '#click' do ... end
describe '#double_click', requires: [:js] do ... end
describe '#right_click', requires: [:js] do ... end
describe '#send_keys', requires: [:send_keys] do ... end
describe '#execute_script', requires: %i[js es_args] do ... end
describe '#evaluate_script', requires: %i[js es_args] do ... end
describe '#evaluate_async_script', requires: %i[js es_args] do ... end
describe '#scroll_to', requires: [:scroll] do ... end
describe '#shadow_root', requires: [:shadow_dom] do ... end
describe '#reload' do ... end
context 'when #synchronize raises server errors' do ... end
end
Import
require 'spec_helper'
Key Test Scenarios
- Text and value retrieval -- Validates
#text,#valuefor inputs, textareas, checkboxes, and radio buttons, including newline preservation - Attribute access -- Tests
#[]for extracting node attributes and boolean attributes likechecked - Style computation -- Verifies
#stylereturns computed CSS property values (requires:csscapability) - Set and input -- Covers
#setfor text fields, readonly elements, contenteditable elements, and global default set options - Tag name, disabled, visible, checked, selected states -- Validates boolean state accessors including fieldset/optgroup disabled propagation
- Equality and path -- Tests
#==identity preservation and#pathXPath resolution including shadow DOM elements - Click interactions -- Single click (checkbox, radio, link, offset, modifier, delay), double click, and right click with W3C offset modes
- Drag and drop -- Native drag-to, HTML5 drag events, Dragula library integration, jsTree integration, and
#dropwith files, strings, and pathnames - Hover -- Hover-triggered visibility changes with scroll support
- Send keys -- String input, special characters, modifier keys, and key event generation
- Script execution --
#execute_scriptand#evaluate_scriptin element context with argument passing and element return support - Scrolling --
#scroll_towith pixel offsets, alignment options, and element targets - Shadow DOM --
#shadow_roottraversal and finding elements within shadow roots - Element reloading -- Manual and automatic reload behavior with and without
Capybara.automatic_reload - Server error synchronization -- Verifies explanatory exception chaining when the application server raises errors during synchronization