Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for shadow_root #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

til
Copy link

@til til commented Apr 29, 2023

Capybara added support to access an element's shadow DOM with Element#shadow_root in teamcapybara/capybara#2546 – it would be nice if Cuprite supported it too.

Here is an attempt at that. Not sure if it does everything as it should, but the specs are passing locally and I've used it successfully in a project's test suite where

# this
expect(
  evaluate_script('arguments[0].shadowRoot', page.find('.a-shadow-host'))
).to have_selector('.inside-shadow-dom')

# could be replaced with this
expect(
  page.find('.a-shadow-host').shadow_root
).to have_selector('.inside-shadow-dom')

The spec "produces error messages when failing" provided by Capybara needed to be adapted because the generated error message includes the value of tagName which is different between Selenium and Cuprite.

The added spec "extends visibility check across shadow host boundary" covers a behaviour that Selenium implements this way: the visibility of the shadow propagates down to its children.

@til til force-pushed the initial-shadow-root-support branch from bff3d8f to ceb4f86 Compare December 9, 2023 12:35
@tomdracz
Copy link

FWIW I've been playing around fixing some Shadow DOM issue using https://github.com/yuki24/capybara-shadowdom It still didn't play ball with likes of clicks not working because of some overlapping element issues.

let element = node.getRootNode().elementFromPoint(x, y); in this PR seems to be the magic sauce so having this available would be neat

@til til force-pushed the initial-shadow-root-support branch from ceb4f86 to 1578943 Compare March 23, 2024 14:36
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.

None yet

2 participants