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

feat: Support shadow DOM recursive selectors inside cypress snapshots sent to protocol #28823

Merged
merged 19 commits into from
Mar 12, 2024

Conversation

AtofStryker
Copy link
Contributor

@AtofStryker AtofStryker commented Jan 30, 2024

  • Closes N/A

Additional details

This PR changes the expected structure of elementsToHighlight in the snapshot code to support shadowDom.

Instead of just returning a selector key with a frameId, the JSON structure now follows an array structure of selectors, starting with the first index being the node element that lives inside the root document, while the last element is the node contained inside the shadow DOM. Any element in between is a shadow DOM host element where the document/ shadow DOM ends and the next shadowDOM begins. This is in order to support N layers deep of shadow DOM.

That structure would look something like this:

{
  "elementsToHighlight": [
    {
      "selector": ["#shadow-root", "#nested-shadow", "#foo"],
      "frameId": "bar"
    }
  ]
}

In the event an element is not within the shadow DOM (i.e. what is supported today), the structure might look something like this:

{
  "elementsToHighlight": [
    {
      "selector": ["#foo"],
      "frameId": "bar",
    }
  ]
}

Steps to test

E2E tests inside the driver have been added to verify the new snapshot structure, as well as a system test in the protocol code to make sure the correct structure is generated.

For the scroll behavior, only an E2E test was added to verify the happy path.

How has the user experience changed?

PR Tasks

@AtofStryker AtofStryker changed the title feat: protocol shadow dom support chore: protocol shadow dom support Jan 30, 2024
@AtofStryker
Copy link
Contributor Author

I also looked into possibly supporting the shadow DOM for snapshots in open mode in a68faa5, which could be used to address #8843. The trick is we need to hydrate the shadow DOM state after a given snapshot from the actual body reference, which means iterating through and cloning the shadow DOM elements. In addition, this has basic support for adoptedStyleSheets. Since we cant created CSSStyleSheets in a detached document or push references from different origin documents (see exceptions, we have to store the style sheets for a later time to be hydrated onto the page after the snapshot document is attached.

shadow dom snapshots not working

no-shadow-dom

shadow dom snapshots working

shadow-dom

@AtofStryker AtofStryker marked this pull request as ready for review January 30, 2024 01:42
Copy link

cypress bot commented Jan 30, 2024

1 failed and 8 flaky tests on run #54477 ↗︎

1 29104 1324 11 Flakiness 8

Details:

Merge branch 'develop' of github.com:cypress-io/cypress into feat/protocol_shado...
Project: cypress Commit: baf229bfad
Status: Failed Duration: 18:54 💡
Started: Mar 12, 2024 4:33 PM Ended: Mar 12, 2024 4:52 PM
Failed  cypress/e2e/create-react-app.cy.ts • 1 failed test • webpack-dev-server

View Output

Test Artifacts
Working with cra-4 > should mount a passing test Test Replay Screenshots
Flakiness  specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e

View Output

Test Artifacts
App/Cloud Integration - Latest runs and Average duration > when no runs are recorded > shows placeholders for all visible specs Test Replay Screenshots
Flakiness  project-setup.cy.ts • 1 flaky test • launchpad-e2e

View Output

Test Artifacts
... > can reconfigure config after CT has been set up Test Replay Screenshots
Flakiness  commands/waiting.cy.js • 1 flaky test • 5x-driver-chrome

View Output

Test Artifacts
... > errors > throws when waiting for 2nd response to route Test Replay
Flakiness  e2e/origin/commands/waiting.cy.ts • 1 flaky test • 5x-driver-chrome

View Output

Test Artifacts
... > throws when foo cannot resolve Test Replay
Flakiness  e2e/origin/basic_login.cy.ts • 1 flaky test • 5x-driver-firefox

View Output

Test Artifacts
Multi-step Auth > final auth redirects back to approval page - flat
    </td>
  </tr></table>

The first 5 flaky specs are shown, see all 8 specs in Cypress Cloud.

Review all test suite changes for PR #28823 ↗︎

@AtofStryker AtofStryker marked this pull request as draft February 1, 2024 15:19
@AtofStryker AtofStryker force-pushed the feat/protocol_shadow_dom_support branch 2 times, most recently from f297e42 to 1f580df Compare February 19, 2024 20:03
@AtofStryker AtofStryker force-pushed the feat/protocol_shadow_dom_support branch from 191e8a3 to 2bddb6d Compare February 26, 2024 16:11
@AtofStryker AtofStryker force-pushed the feat/protocol_shadow_dom_support branch 3 times, most recently from 5f31493 to e0a6e9d Compare February 26, 2024 16:17
@AtofStryker AtofStryker force-pushed the feat/protocol_shadow_dom_support branch from e0a6e9d to 1dc0e9b Compare February 26, 2024 16:18

it('does not have cypress errors when visiting closed shadow roots', () => {
cy.visit('cypress/fixtures/shadow-dom-closed.html')
cy.get('#in-shadow', { includeShadowDom: true }).should('not.exist')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test is likely a good add to make sure we don't introduce something that could cause the app to implode if a closed shadow root is inside the AUT

@AtofStryker AtofStryker self-assigned this Feb 27, 2024
@AtofStryker AtofStryker marked this pull request as ready for review February 27, 2024 13:48
@AtofStryker AtofStryker changed the title chore: protocol shadow dom support chore: Support shadow DOM recursive selectors inside cypress snapshots sent to protocol Feb 27, 2024
@AtofStryker
Copy link
Contributor Author

@ryanthemanuel @mschile not sure if we want to make this a feat or a chore since it doesn't really have an effect on the app?

@ryanthemanuel
Copy link
Collaborator

@ryanthemanuel @mschile not sure if we want to make this a feat or a chore since it doesn't really have an effect on the app?

I'd make it a feature. We've called out Test Replay functionality changes before in that regard.

@AtofStryker AtofStryker changed the title chore: Support shadow DOM recursive selectors inside cypress snapshots sent to protocol feat: Support shadow DOM recursive selectors inside cypress snapshots sent to protocol Feb 28, 2024
@jennifer-shehane jennifer-shehane merged commit 7a7a28f into develop Mar 12, 2024
94 of 107 checks passed
@jennifer-shehane jennifer-shehane deleted the feat/protocol_shadow_dom_support branch March 12, 2024 16:29
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 13, 2024

Released in 13.7.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.7.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants