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

Merged

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 #63295

Run Properties:  status check passed Passed #63295  •  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 passed Passed #63295
Run duration 17m 07s
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 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 133
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5553
View all changes introduced in this branch ↗︎

@@ -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
@jennifer-shehane jennifer-shehane merged commit 850989e into release/15.0.0 Jun 26, 2025
79 of 85 checks passed
@jennifer-shehane jennifer-shehane deleted the selector-playground-api-to-element-selector branch June 26, 2025 15:08
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