Skip to content

Cuprite support#157

Open
myabc wants to merge 3 commits into
citizensadvice:mainfrom
opf:feature/cuprite-support
Open

Cuprite support#157
myabc wants to merge 3 commits into
citizensadvice:mainfrom
opf:feature/cuprite-support

Conversation

@myabc
Copy link
Copy Markdown

@myabc myabc commented Nov 13, 2025

Summary

  • Adds Cuprite as an alternative headless Chrome driver, using CDP Accessibility.getPartialAXTree to resolve computed accessible names, roles, and descriptions
  • Skips specs that rely on Selenium-specific behaviour when running under Cuprite

Test plan

  • bundle exec rspec (default Selenium driver) — 1812 examples, 0 failures
  • DRIVER=cuprite_chrome_headless bundle exec rspec — 1812 examples, 0 failures, 14 expected pending

Comment thread lib/capybara_accessible_selectors/node.rb Outdated
Comment thread spec/spec_helper.rb Outdated
Capybara::Selenium::Driver.new(app, browser: :chrome, options:)
end
Capybara.register_driver(:cuprite_chrome_headless) do |app|
Capybara::Cuprite::Driver.new(app, browser_name: :chrome)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lib/capybara_accessible_selectors/node/accessible_description.rb Outdated
@myabc
Copy link
Copy Markdown
Author

myabc commented Apr 3, 2026

@seanpdoyle thanks for your feedback and apologies for dropping the ball! I'd still love to see Cuprite support. I'll see if I can address the various comments in the next week or so.

@myabc myabc force-pushed the feature/cuprite-support branch 2 times, most recently from 58bb24e to 88d327c Compare April 4, 2026 16:33
@myabc myabc marked this pull request as ready for review April 4, 2026 16:33
Copilot AI review requested due to automatic review settings April 4, 2026 16:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial support for running this project’s Capybara accessible selectors against the Cuprite (Ferrum/CDP) driver by introducing Cuprite-based computed accessibility queries and wiring Cuprite into the test suite.

Changes:

  • Add Cuprite driver registration in the RSpec spec helper and introduce driver-based skips for known-incompatible specs.
  • Implement Cuprite-backed accessible_name, accessible_description, and role resolution using a new AccessibilityComputedValue helper.
  • Update rich text filling to avoid sending nil/empty values, and add Cuprite to the bundle.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
spec/spec_helper.rb Optionally requires Cuprite and registers a Cuprite headless driver for specs.
spec/selectors/rich_text_spec.rb Skips specific rich-text behavior tests for Cuprite.
spec/selectors/disclosure_spec.rb Skips specific disclosure toggle/select tests for Cuprite.
spec/capybara/node/element/accessible_description_spec.rb Skips specific accessible-description expectations for Cuprite.
lib/capybara_accessible_selectors/selectors/rich_text.rb Avoids sending nil text and removes Selenium platform dependency for modifier key detection.
lib/capybara_accessible_selectors/rspec/matchers/have_validation_errors.rb Adjusts outerHTML retrieval to support drivers without attribute('outerHTML').
lib/capybara_accessible_selectors/node/role.rb Adds Cuprite-specific role resolution.
lib/capybara_accessible_selectors/node/accessible_name.rb Adds Cuprite-specific accessible name resolution.
lib/capybara_accessible_selectors/node/accessible_description.rb Adds Cuprite-specific accessible description resolution.
lib/capybara_accessible_selectors/node.rb Includes Cuprite node extensions when Cuprite is already loaded.
lib/capybara_accessible_selectors/cuprite/accessibility_computed_value.rb New helper to query computed accessibility values via CDP.
Gemfile / Gemfile.lock Adds Cuprite dependency and updates the lockfile.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/capybara_accessible_selectors/node/role.rb Outdated
Comment thread lib/capybara_accessible_selectors/node/accessible_name.rb Outdated
Comment thread lib/capybara_accessible_selectors/node/accessible_description.rb Outdated
Comment thread lib/capybara_accessible_selectors/node.rb
@myabc myabc force-pushed the feature/cuprite-support branch from 88d327c to 89ae084 Compare April 4, 2026 16:47
myabc added 2 commits April 4, 2026 18:12
Add Cuprite (Chrome DevTools Protocol) as an alternative browser driver.
Uses Chrome's Accessibility.getPartialAXTree CDP command to resolve
accessible name, description, and role values.

- Add CupriteNodeExtensions with defined? guard for optional dependency
- Add AccessibilityComputedValue resolver for CDP accessibility tree
- Handle Chrome's non-standard PascalCase role identifiers
- Guard Cuprite require/registration in spec_helper
- Use RUBY_PLATFORM for platform detection (no hard Selenium dependency)
- Use evaluate_script for outerHTML access across drivers
- Add send_keys nil guards for rich text

Fixes citizensadvice#156
Annotate specs with skip_driver: :cuprite_chrome where Chrome's CDP
accessibility tree returns different values than Selenium, or where
Cuprite's send_keys handling of modifier keys differs.

- 4 accessible_description edge cases (browser implementation differences)
- 2 disclosure toggle/select specs (details element interaction)
- 8 rich text fill/replace/within specs (modifier key handling)
@myabc myabc force-pushed the feature/cuprite-support branch from 89ae084 to 810bde3 Compare April 4, 2026 17:12
# So we can't just use backspace
input.send_keys [command_modifier, "a"], :backspace if input.text != "" && clear
input.send_keys with
input.send_keys with if with
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: would be good to fix upstream!

Comment thread spec/spec_helper.rb
Comment on lines +11 to +15
begin
require "capybara/cuprite"
rescue LoadError
# Cuprite is optional
end
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is necessary - it might be ok to make Cuprite (and all Capybara drivers) test dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants