Skip to content

feat: Rename SelectorPlayground API to ElementSelector API #31889

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

Open
wants to merge 22 commits into
base: release/15.0.0
Choose a base branch
from

Conversation

jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Jun 13, 2025

Additional details

  • Renames SelectorPlayground API to ElementSelector - an error is thrown when users use the SelectorPlayground API.
  • Removes 'onElement' property from 'defaults' - we don't intend to support this custom selector definition anymore (it has extremely low usage)
  • Bumps unique-selector package to latest - this should bring in smarter selectors and an expanded API.
  • Loosen the types of selectors that can be specified in priority - we now support name and attribute:* selectors as they are accepted in unique-selector. Types are now more specific also.
  • Converts files from JS to TS

Steps to test

  1. Use the existing Selector Playground UI - ensuring it adds selectors properly - accepting selectorPriority.
  2. Use the existing experimentalStudio UI - ensuring it adds selectors properly - accepting selectorPriority.
  3. Ensure calling SelectorPlayground API properly errors and is shown as deprecated in TypeScript.

How has the user experience changed?

Cypress.SelectorPlayground errors when called

Screenshot 2025-06-20 at 1 06 15 PM

Can now use name attribute in selectorPriority!
Screenshot 2025-06-20 at 1 06 55 PM

Can now use attribute:* in selectorPriority!
Screenshot 2025-06-20 at 1 07 44 PM

Current studio selector generation still works!
Screenshot 2025-06-20 at 1 30 45 PM

PR Tasks

BREAKING: Rename SelectorPriority API to ElementSelector API
@jennifer-shehane jennifer-shehane changed the base branch from develop to release/15.0.0 June 13, 2025 17:34
@jennifer-shehane jennifer-shehane changed the title Selector playground api to element selector feat: Rename SelectorPlayground API to ElementSelector API Jun 13, 2025
Copy link

cypress bot commented Jun 13, 2025

cypress    Run #63279

Run Properties:  status check failed Failed #63279  •  git commit d1c4948a9d: Merge branch 'release/15.0.0' into selector-playground-api-to-element-selector
Project cypress
Branch Review selector-playground-api-to-element-selector
Run status status check failed Failed #63279
Run duration 16m 59s
Commit git commit d1c4948a9d: Merge branch 'release/15.0.0' into selector-playground-api-to-element-selector
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 143
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 6163
View all changes introduced in this branch ↗︎
UI Coverage  0%
  Untested elements 4  
  Tested elements 0  
Accessibility  97.09%
  Failed rules  0 critical   1 serious   0 moderate   0 minor
  Failed elements 4  

Tests for review

Failed  cypress/e2e/commands/files.cy.js • 1 failed test • 5x-driver-firefox

View Output

Test Artifacts
src/cy/commands/files > #readFile > retries to read when ENOENT
    </td>
  </tr></table>
Flakiness  issues/28527.cy.ts • 1 flaky test • 5x-driver-firefox

View Output

Test Artifacts
issue 28527 > fails and then retries and verifies about:blank is not displayed Screenshots
Flakiness  studio/studio.cy.ts • 2 flaky tests • app-e2e

View Output

Test Artifacts
Cypress Studio > does not create a new test if the Save test modal is closed Test Replay Screenshots
Cypress Studio > remains in studio mode when the test name is changed on the file system and file watching is disabled Test Replay Screenshots

@@ -0,0 +1,86 @@
/// <reference types="cypress" />
Copy link
Member Author

Choose a reason for hiding this comment

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

Converted to TypeScript - the tests are the same except for removing tests around onElement

@@ -0,0 +1,81 @@
/// <reference types="cypress" />
Copy link
Member Author

Choose a reason for hiding this comment

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

Also converted to TS. The content is the same except for removing onElement and renaming element_selector

@jennifer-shehane jennifer-shehane self-assigned this Jun 16, 2025
Copy link
Contributor

@cacieprins cacieprins left a comment

Choose a reason for hiding this comment

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

Just a couple nits regarding types - looks good!


const VALID_SELECTOR_PRIORITY_REGEX = /^(data\-.+|id|class|tag|attributes|nth\-child|attribute:(.+)|name)$/

export const DEFAULT_SELECTOR_PRIORITIES = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the values here match the type we export in cypress.d.ts - Cypress.SelectorPriority[]?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll take another look at these comments. I added the cypress types after the fact so probably should have looked back at the code to make sure they make sense together.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is actually the exact selectorPriority that Cypress will pass by default to the unique-selector, not just the TYPE of selector priorities accepted.

'nth-child',
] as const

export type SelectorType = string
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this type, we should probably use Cypress.SelectorPriority, unless we accept strings that are not included in that union.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the Cypress.SelectorPriority to be used everywhere.

@jennifer-shehane
Copy link
Member Author

Pausing on merging this until the Studio side updates handling Cypress.ElementSelector to address the test failure.

@jennifer-shehane jennifer-shehane marked this pull request as draft June 24, 2025 14:32
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.

2 participants