Skip to content

Commit e3010e3

Browse files
jennifer-shehaneAtofStrykerMikeMcC399danjohansenconsultingcacieprins
authored
docs: Breaking: Cypress 15.0.0 (#6137)
* chore: remove CDP deprecation notice in launching browsers related to firefox (#6116) * chore: Node.js 18/23 removal (#6138) * Update Node.js versions that will be supported for 15 * update lowest npm version supported * chore: update typescript docs to tsx (#6155) * chore: remove ts-node references and workarounds and replace them with tsx * add empty changelog entry for 15 to allow for linked out changes to build * chore: add beginning of migration guide for Cypress 15 (#6159) * chore: add begining of migration guide for Cypress 15 * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> --------- Co-authored-by: Mike McCready <[email protected]> * chore: make the minimum version of angular 18+ (#6168) * chore: add webpack 4 migration guide / workarounds (#6164) * chore: merge dev into 15 (#6172) * Add Windows 2025 to supported OS list (#6142) * New user roles and permissions defined (#6143) * chore: release 14.3.0 documentation (#6144) * feat: documentation for the press() command (#6135) * docs for the press() command, including a callout in the accessibility guide * add press to TOC * Move some content around, mention accesiibility * remove 'focus' note * Document Keyboard.Keys * update reference to command * Update example to be a little more real case * Add another example of autocomplete with tab * Add link to keyboard api page * Fix version number for introduction * Fix broken link * alphabetize see also * Update package.json Co-authored-by: Mike McCready <[email protected]> * Fix broken link * lint --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Mike McCready <[email protected]> * chore: add 14.3.0 changelog to documentation * Update docs/app/guides/accessibility-testing.mdx * Update docs/app/references/changelog.mdx Co-authored-by: Bill Glesias <[email protected]> --------- Co-authored-by: Cacie Prins <[email protected]> Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Mike McCready <[email protected]> * Correct parameter usage for click() in shadow.mdx (#6145) * Update shadow.mdx - Update the suggestion to pass 'top' to cy.click() using the options defined in cy.click()'s documentation * Update shadow.mdx Add missing quote * Update shadow.mdx One-line for prettier reasons * Correct command syntax (#6148) Adds the missing `s` to `Cypress.Command.overwrite()` * extend pnpm config instructions (#6149) * fix cy.origin() "yielding a value" example (#6152) * Update results-api.mdx (#6150) * chore: add 14.3.1 changelog (#6153) * chore: add 14.3.1 changelog * Update docs/app/references/changelog.mdx Co-authored-by: Mike McCready <[email protected]> * empty commit to rekick build --------- Co-authored-by: Mike McCready <[email protected]> * docs: harmonize on injectDocumentDomain removal in future version (#6154) * Add experimentalSessionAndOrigin removed comment to origin video (#6158) * Fix "cy.visit() succeeded, but commands are timing out" error example (#6157) * Cross-link cy.origin and injectDocumentDomain (#6156) * chore: add cypress 14.3.2 changelog (#6160) * Change 'add on' to 'premium solution' for UI Cov & a11y products (#6162) * UI Coverage and Branch Review updates (#6167) * add AQ links and button space * use onlinks for demo vids * update Cypress * content updates * content tweaks * add last images * lint-fix * simplify * add detail view docs and clean up * lint fix * Update docs/cloud/get-started/introduction.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/ui-coverage/core-concepts/compare-reports.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/ui-coverage/core-concepts/compare-reports.mdx Co-authored-by: Mike McCready <[email protected]> * revert cypress version bump * restore package-lock * remove yarn lockfile * Update docs/app/get-started/why-cypress.mdx Co-authored-by: Tyler Biethman <[email protected]> * Update docs/cloud/features/branch-review.mdx Co-authored-by: Tyler Biethman <[email protected]> * Update docs/cloud/features/branch-review.mdx Co-authored-by: Tyler Biethman <[email protected]> --------- Co-authored-by: Mike McCready <[email protected]> Co-authored-by: Tyler Biethman <[email protected]> * chore: add 14.3.3 changelog (#6171) * chore: add 14.3.3 changelog * Update docs/app/references/changelog.mdx Co-authored-by: Matt Schile <[email protected]> --------- Co-authored-by: Matt Schile <[email protected]> * Rework instructions for missing Cypress binary in CI (#6170) * Node.js 18 EOL (#6165) * Add quoting advice for PowerShell CLI options (#6169) * Add quoting advice for PowerShell CLI options * Fix --config typo Co-authored-by: Jennifer Shehane <[email protected]> --------- Co-authored-by: Jennifer Shehane <[email protected]> * Bump Cypress Docker versions in examples to Node.js 22.15.0 LTS (#6161) --------- Co-authored-by: Mike McCready <[email protected]> Co-authored-by: danjohansenconsulting <[email protected]> Co-authored-by: Cacie Prins <[email protected]> Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Matthew Sbar <[email protected]> Co-authored-by: Tim Rayers <[email protected]> Co-authored-by: Emily Wisniewski (Rohrbough) <[email protected]> Co-authored-by: Mark Noonan <[email protected]> Co-authored-by: Tyler Biethman <[email protected]> Co-authored-by: Matt Schile <[email protected]> Co-authored-by: Jennifer Shehane <[email protected]> * Revert "chore: merge dev into 15 (#6172)" (#6174) This reverts commit 6af2913. * chore: add migration guide for`@cypress/webpack-batteries-included-preprocessor` built-ins removal (#6192) * chore: add migration guide if needing webpack built-ins * Update docs/app/references/migration-guide.mdx Co-authored-by: Jennifer Shehane <[email protected]> * run linter --------- Co-authored-by: Jennifer Shehane <[email protected]> * baseline updates for Cypress Studio updates * Updates for renaming SelectorPlayground to ElementSelector API (#6212) * Updates for SelectorPlayground to ElementSelector * add migration section for SelectorPlayground renaming * remove links to selector-playgroun-api * lint * Update docs/app/references/migration-guide.mdx Co-authored-by: Emily Wisniewski (Rohrbough) <[email protected]> * Update docs/app/references/migration-guide.mdx Co-authored-by: Emily Wisniewski (Rohrbough) <[email protected]> * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/api/cypress-api/element-selector-api.mdx Co-authored-by: Mike McCready <[email protected]> * remove note about Node.js 18 being deprecated * Update docs/app/guides/cypress-studio.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> * docs: minimum linux requirements for electron 36 (#6219) * minimum linux requirements for electron 36 * fix deb 10 ref for cy 14 * rm tables, make concise * Update docs/app/get-started/install-cypress.mdx * Update docs/app/references/migration-guide.mdx * Update docs/app/references/migration-guide.mdx Co-authored-by: Mike McCready <[email protected]> --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Mike McCready <[email protected]> * chore: document vite 4 removal and vite 7 support for ct (#6224) * Rewrite to make its use more understandable + remove getSelector (#6235) * Rewrite to make its use more understandable + remove getSelector * Add more examples + simplify * lint * add note about uniqueness of selector * lint * Remove redundant aria-label * Add notes about the variability of the ElementSelector API and the de… (#6238) * Add notes about the variability of the ElementSelector API and the deprecation of Selector Playground * update info areas * lint fix * Add new screenshots that match Cypress 15 design (#6240) * begin added images of newly designed app * add more 15 images * lint * Add more specific content + videos for Studio (#6245) * Add a video for editing in studio * More updates for Studio docs * lint fix * add last video * Add limitation around cypress/grep + existing issues link * chore: update CT docs and migration guide (#6248) * chore: update docs with supported angular versions, webpack versions, and migration guide helpers * fix linter issues --------- Co-authored-by: Jennifer Shehane <[email protected]> * chore: update code to exitCode in `cy.exec()` (#6247) * chore: update code to exitCode * add history to exec * Add short migration descriptions * chore: fix linter issues --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Jennifer Shehane <[email protected]> * Update install page to remove direct download (#6249) * Update install page * lint + link fix * typo * typo * Update docs/app/get-started/install-cypress.mdx Co-authored-by: Mike McCready <[email protected]> * updates for broken links + semver versions + ubuntu/debian updates * lint * lint --------- Co-authored-by: Mike McCready <[email protected]> * commit summary for changelog * chore: add Release 15.0.0 changelog (#6252) --------- Co-authored-by: Bill Glesias <[email protected]> Co-authored-by: Mike McCready <[email protected]> Co-authored-by: danjohansenconsulting <[email protected]> Co-authored-by: Cacie Prins <[email protected]> Co-authored-by: Matthew Sbar <[email protected]> Co-authored-by: Tim Rayers <[email protected]> Co-authored-by: Emily Wisniewski (Rohrbough) <[email protected]> Co-authored-by: Mark Noonan <[email protected]> Co-authored-by: Tyler Biethman <[email protected]> Co-authored-by: Matt Schile <[email protected]>
1 parent a3c0cc9 commit e3010e3

File tree

75 files changed

+735
-725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+735
-725
lines changed

docs/api/commands/exec.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Pass in an options object to change the default behavior of `cy.exec()`.
5757

5858
`cy.exec()` yields an object with the following properties:
5959

60-
- `code`
60+
- `exitCode`
6161
- `stdout`
6262
- `stderr`
6363

@@ -80,7 +80,7 @@ is great for:
8080
cy.exec('npm run build').then((result) => {
8181
// yields the 'result' object
8282
// {
83-
// code: 0,
83+
// exitCode: 0,
8484
// stdout: "Files successfully built",
8585
// stderr: ""
8686
// }
@@ -90,7 +90,7 @@ cy.exec('npm run build').then((result) => {
9090
#### Seed the database and assert it was successful
9191

9292
```javascript
93-
cy.exec('rake db:seed').its('code').should('eq', 0)
93+
cy.exec('rake db:seed').its('exitCode').should('eq', 0)
9494
```
9595

9696
#### Run an arbitrary script and assert its output
@@ -133,7 +133,7 @@ cy.exec('npm run build', { timeout: 20000 })
133133

134134
```javascript
135135
cy.exec('man bear pig', { failOnNonZeroExit: false }).then((result) => {
136-
expect(result.code).to.eq(1)
136+
expect(result.exitCode).to.eq(1)
137137
expect(result.stderr).to.contain('No manual entry for bear')
138138
})
139139
```
@@ -237,6 +237,12 @@ the following:
237237
alt="console.log exec"
238238
/>
239239

240+
## History
241+
242+
| Version | Changes |
243+
| ------------------------------------------ | ------------------------------------- |
244+
| [15.0.0](/app/references/changelog#15-0-0) | Renamed property `code` to `exitCode` |
245+
240246
## See also
241247

242248
- [`cy.readFile()`](/api/commands/readfile)
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
title: 'Cypress.ElementSelector | Cypress Documentation'
3+
description: 'Customize how Cypress chooses selectors in Studio and Selector Playground by setting your preferred selector strategy.'
4+
sidebar_label: ElementSelector
5+
sidebar_position: 105
6+
---
7+
8+
<ProductHeading product="app" />
9+
10+
# Cypress.ElementSelector
11+
12+
The ElementSelector API lets you define how Cypress selects elements in tools like [Cypress Studio](/app/guides/cypress-studio) and the [Selector Playground](/app/core-concepts/open-mode#Selector-Playground) (which will be replaced by Cypress Studio once it is no longer experimental).
13+
14+
By setting your own selector strategy, you can control which attributes Cypress prioritizes (like `data-*`, `id`, or `aria-label`) when generating selectors. This helps you enforce consistency, improve test readability, and make generated tests more resilient to changes in your HTML.
15+
16+
Cypress uses a strategy to generate selectors that are not only based on your preferred selectors, but also guaranteed to be **unique** within the document.
17+
18+
This means Cypress will **attempt to follow your configured `selectorPriority`**, but may skip lower-priority options or combine multiple selectors if a single attribute isn't unique enough.
19+
20+
## Syntax
21+
22+
```javascript
23+
Cypress.ElementSelector.defaults(options)
24+
```
25+
26+
### Arguments
27+
28+
<Icon name="angle-right" /> **options _(Object)_**
29+
30+
An object containing any or all of the following options:
31+
32+
| Option | Accepts | Description |
33+
| ------------------ | ------------------ | ---------------------------------------------------------------------- |
34+
| `selectorPriority` | `Array of strings` | Determines the order of attributes Cypress uses to generate selectors. |
35+
36+
:::info
37+
38+
##### API Stability
39+
40+
The `selectorPriority` API is under active development and may change in future versions as we refine the best way to generate selectors within our products. Stay updated with our [changelog](/app/references/changelog) for any breaking changes.
41+
42+
:::
43+
44+
Accepted values for `selectorPriority` are:
45+
46+
- `attribute:${string}` - for specific attributes like `attribute:aria-label`, `attribute:lang`, etc.
47+
- `attributes` - general fallback for any other attributes
48+
- `class`
49+
- `data-${string}` - for specific data attributes like `data-cy`, `data-testid`, etc.
50+
- `id`
51+
- `name`
52+
- `nth-child`
53+
- `tag`
54+
55+
<DefaultSelectorPriority />
56+
57+
Consider the following HTML:
58+
59+
```html
60+
<button id="submit-btn" class="primary" role="button" aria-label="Submit">
61+
Submit
62+
</button>
63+
```
64+
65+
With the default selector priority, Cypress prioritizes `id`, so the selector would be `#submit-btn`.
66+
67+
<Icon name="angle-right" /> **$el _(Object)_**
68+
69+
The [jQuery element](http://api.jquery.com/Types/#jQuery) for which you want to retrieve a selector.
70+
71+
## Examples
72+
73+
### Set custom selector priority
74+
75+
You can customize how Cypress generates selectors by defining a priority order for which attributes to prefer. This affects the selectors you see in tools like [Cypress Studio](/app/guides/cypress-studio) and the [Selector Playground](/app/core-concepts/open-mode#Selector-Playground) (which will be replaced by Cypress Studio once it is no longer experimental).
76+
77+
For example, this config tells Cypress to prefer semantic and accessibility attributes before falling back to styling details like class names.
78+
79+
```javascript
80+
Cypress.ElementSelector.defaults({
81+
selectorPriority: [
82+
'attribute:role',
83+
'attribute:aria-label',
84+
'name',
85+
'class',
86+
'attributes',
87+
],
88+
})
89+
```
90+
91+
### Prioritize accessible attributes
92+
93+
Accessibility-first apps often use ARIA roles and labels. You can configure Cypress to prioritize these when generating selectors:
94+
95+
```js
96+
Cypress.ElementSelector.defaults({
97+
selectorPriority: ['attribute:aria-label', 'attribute:role', 'id', 'class'],
98+
})
99+
```
100+
101+
This helps produce more readable and resilient selectors, especially for accessibility-first applications.
102+
103+
### Prioritize language-agnostic selectors (for i18n)
104+
105+
In multilingual applications, selectors based on text or labels may change between locales. Prefer stable, language-agnostic attributes like `data-*`, `role`, and `aria-labelledby`.
106+
107+
```js
108+
Cypress.ElementSelector.defaults({
109+
selectorPriority: [
110+
'data-cy',
111+
'attribute:role',
112+
'attribute:aria-labelledby',
113+
'name',
114+
'id',
115+
'class',
116+
'attributes',
117+
],
118+
})
119+
```
120+
121+
This ensures selectors are resilient to translation changes in text or labels.
122+
123+
### Avoid dynamic or auto-generated selectors
124+
125+
Many frameworks produce dynamic ids or class names such as:
126+
127+
```html
128+
<button
129+
id="button-5a3f9d"
130+
class="Component_button__3XyZ2 css-1a2b3c SeriesIndexFooter-footer-3WmRg"
131+
data-cy="checkout-btn"
132+
>
133+
Checkout
134+
</button>
135+
```
136+
137+
You can configure Cypress to skip attributes that are dynamically generated.
138+
139+
```js
140+
Cypress.ElementSelector.defaults({
141+
selectorPriority: [
142+
'data-cy',
143+
'attribute:role',
144+
'attribute:aria-label',
145+
'name',
146+
'attributes', // fallback
147+
// deliberately omit 'id' and 'class'
148+
],
149+
})
150+
```
151+
152+
## History
153+
154+
| Version | Changes |
155+
| ------------------------------------------ | ------------------------------------------------------------------ |
156+
| [15.0.0](/app/references/changelog#15-0-0) | Renamed `Cypress.SelectorPlayground` to `Cypress.ElementSelector`. |
157+
158+
## See also
159+
160+
- [Cypress Studio](/app/guides/cypress-studio)
161+
- [Selector Playground](/app/core-concepts/open-mode#Selector-Playground)

docs/api/cypress-api/selector-playground-api.mdx

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)