From 2ea2abb4363bdb503b216a6d3ed995f03a5553bd Mon Sep 17 00:00:00 2001 From: Cacie Prins <cacie@cypress.io> Date: Fri, 28 Mar 2025 15:38:19 -0400 Subject: [PATCH 01/15] docs for the press() command, including a callout in the accessibility guide --- docs/api/commands/focus.mdx | 1 + docs/api/commands/press.mdx | 112 ++++++++++++++++++++++ docs/api/commands/type.mdx | 1 + docs/app/guides/accessibility-testing.mdx | 7 ++ package.json | 3 +- 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 docs/api/commands/press.mdx diff --git a/docs/api/commands/focus.mdx b/docs/api/commands/focus.mdx index 36024d875a..ea7c350832 100644 --- a/docs/api/commands/focus.mdx +++ b/docs/api/commands/focus.mdx @@ -159,4 +159,5 @@ the following: - [`.blur()`](/api/commands/blur) - [`.click()`](/api/commands/click) - [`cy.focused()`](/api/commands/focused) +- [`.press()`](/api/commands/press) - [`.type()`](/api/commands/type) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx new file mode 100644 index 0000000000..950f38d6cc --- /dev/null +++ b/docs/api/commands/press.mdx @@ -0,0 +1,112 @@ +--- +title: 'press | Cypress Documentation' +description: Dispatch a series of native key events to your application +sidebar_label: press +slug: /api/commands/press +componentSpecific: false +--- + +<ProductHeading product="app" /> + +# press + +Dispatch a series of native key events to your application. + +A keydown, press, and keyup event will be dispatched directly to the browser window. Note that your application must have focus to properly receive this event. It can be helpful to use `cy.focus()` to ensure focus on an element in your application before using this command. + +This command is distinct from `cy.type()`: it is meant for non-character keys, will dispatch real keyboard events rather than simulated ones. Currently, the only key support is `Tab`. + +This command is _not_ chainable, and does not return a value. + +:::info + +<strong>Supported Browsers:</strong> +This command is supported in chromium browsers, and Firefox versions beginning with +v135. Safari is not supported. This command will fail if executed in a browser that +does not support it. + +::: + +:::caution + +<Icon name="exclamation-triangle" /> **Transient activation** + +By dispatching native keyboard events to the browser, this command will cause the browser to enter [Transient activation](https://developer.mozilla.org/en-US/docs/Glossary/Transient_activation) state. + +If your application prevents the default behavior of the `beforeunload` event, this may cause issues when navigating away from the current page. + +::: + +## Syntax + +```javascript +cy.press(Cypress.Keyboard.Keys.TAB) +cy.press(Cypress.Keyboard.Keys.TAB, { + log: false, + timeout: 2000, +}) +``` + +## Signature + +```typescript +interface PressCommand { + ( + key: KeyPressSupportedKeys, + options?: Partial<Cypress.Loggable> & Partial<Cypress.Timeoutable> + ): void +} +``` + +## Usage + +<Icon name="check-circle" color="green" /> **Correct Usage** + +```javascript +it('moves focus to the next form element when the user presses tab', function () { + cy.visit('/my-form') + cy.get('input.first').focus() // focusing the first form element ensures that the application will receive the events + cy.press(Cypress.Keyboard.Keys.TAB) + cy.get('input.second').should('have.focus') +}) +``` + +<Icon name="exclamation-triangle" color="red" /> **Incorrect Usage** + +```javascript +it('moves focus to the next form element when the user presses tab', function () { + cy.visit('/my-form') + cy.press(Cypress.Keyboard.Keys.TAB) // the key event will be dispatched to the top frame, rather than your application + cy.get('input.second').should('have.focus') // the key events did not get dispatched to the application, so the focus did not shift to the second form element. +}) +``` + +### Arguments + +<Icon name="angle-right" /> **key _(String)_** + +The key to press. The supported values are available on `Cypress.Keyboard.Keys`, and may change from time to time. It is recomended that you reference these values from `Cypress.Keyboard.Keys` rather than passing in a string. + +### Supported Keys + +| Reference | Value | +| --------------------------- | ------- | +| `Cypress.Keyboard.Keys.TAB` | `"Tab"` | + +<Icon name="angle-right" /> **options _(Object)_** + +The second `options` parameter is optional and standard for Cypress commands. It supports setting the timeout and/or whether to log the command: + +## History + +| Version | Changes | +| ------------------------------------------ | --------------------------- | +| [14.2.2](/app/references/changelog#14-2-2) | Added the `press()` command | + +## See also + +- [`.focus()`](/api/commands/focus) +- [`.focused()`](/api/commands/focused) +- [`.type()`](/api/commands/type) +- [`.focused()`](/api/) +- [`Cypress.Keyboard`](/api/cypress-api/keyboard-api) diff --git a/docs/api/commands/type.mdx b/docs/api/commands/type.mdx index 075919fa71..46e999f93e 100644 --- a/docs/api/commands/type.mdx +++ b/docs/api/commands/type.mdx @@ -664,5 +664,6 @@ following: - [`.clear()`](/api/commands/clear) - [`.click()`](/api/commands/click) - [`.focus()`](/api/commands/focus) +- [`.press()`](/api/commands/press) - [`.submit()`](/api/commands/submit) - [`Cypress.Keyboard`](/api/cypress-api/keyboard-api) diff --git a/docs/app/guides/accessibility-testing.mdx b/docs/app/guides/accessibility-testing.mdx index 827095944e..62d4e594cf 100644 --- a/docs/app/guides/accessibility-testing.mdx +++ b/docs/app/guides/accessibility-testing.mdx @@ -169,6 +169,13 @@ This means that, without some assertions about either the `button` element itsel Developers who are unfamiliar with accessibility may assume that if a Testing Library `ByRole` locator can be made to pass before and after a code change, there has been no functional or accessibility-related change in the underlying element. As we've seen, this is not actually the case, because of the extra behavior browsers only implement for native HTML elements. For more about this difference and why semantic HTML elements are preferred, see the [first rule of Accessible Rich Internet Applications (ARIA)](https://www.w3.org/TR/using-aria/#rule1). +### Keyboard navigation + +To test intra-page navigation with the keyboard, you can use the [`cy.press()`](/api/commands/press) to dispatch native tab events. + +Note that the application under test does not have focus by default. You must focus an element in your application before it will receive +this event. + ## Where to test accessibility So what should you do in your test automation to help confirm the UI is accessible? First of all, for known critical areas like forms or checkout flows, ensure that the accessibility behavior is tested explicitly in at least one place. The means verifying that form fields and buttons have the correct labels and use the expected HTML elements, and other aspects of the DOM that communicate necessary information. diff --git a/package.json b/package.json index 51219dfc5d..ba38c29ce0 100644 --- a/package.json +++ b/package.json @@ -69,5 +69,6 @@ "last 1 firefox version", "last 1 safari version" ] - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } From c843f74edf6d2b303db8074b2d1ffb86fbbfd29c Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Fri, 28 Mar 2025 16:32:30 -0400 Subject: [PATCH 02/15] add press to TOC --- docs/api/table-of-contents.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/table-of-contents.mdx b/docs/api/table-of-contents.mdx index 693ea90714..20446f398d 100644 --- a/docs/api/table-of-contents.mdx +++ b/docs/api/table-of-contents.mdx @@ -139,6 +139,7 @@ Cypress has a variety of additional commands to help write tests. | [`.mount()`](/api/commands/mount) | Mount a component for Cypress Component Testing. | | [`.origin()`](/api/commands/origin) | Visit multiple domains of different origin in a single test. | | [`.pause()`](/api/commands/pause) | Pause test execution, allowing interaction with the application under test before resuming. | +| [`.press()`](/api/commands/press) | Trigger native key events in your application to simulate real user keyboard interactions. | | [`.readFile()`](/api/commands/readfile) | Read a file from disk. | | [`.reload()`](/api/commands/reload) | Reload the page. | | [`.request()`](/api/commands/request) | Make an HTTP request. | From 61ca78c72e60608dc31be74abb6a003d6d6e827a Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Fri, 28 Mar 2025 16:45:37 -0400 Subject: [PATCH 03/15] Move some content around, mention accesiibility --- docs/api/commands/press.mdx | 89 +++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index 950f38d6cc..4c1258dda1 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -1,6 +1,6 @@ --- -title: 'press | Cypress Documentation' -description: Dispatch a series of native key events to your application +title: 'cy.press() | Cypress Documentation' +description: Trigger native key events in your application to simulate keyboard interactions. sidebar_label: press slug: /api/commands/press componentSpecific: false @@ -10,41 +10,28 @@ componentSpecific: false # press -Dispatch a series of native key events to your application. +Trigger native key events in your application to simulate keyboard interactions. -A keydown, press, and keyup event will be dispatched directly to the browser window. Note that your application must have focus to properly receive this event. It can be helpful to use `cy.focus()` to ensure focus on an element in your application before using this command. +A `keydown`, `press`, and `keyup` event will be dispatched directly to the browser window. Note that your application must have focus to properly receive this event. It can be helpful to use `cy.focus()` to ensure focus on an element in your application before using this command. -This command is distinct from `cy.type()`: it is meant for non-character keys, will dispatch real keyboard events rather than simulated ones. Currently, the only key support is `Tab`. +Unlike `cy.type()`, which is best for typing character keys, `cy.press()` will dispatch real keyboard events rather than simulated ones. This command is especially useful when testing focus management and keyboard navigation patterns which are critical for [accessibility testing](/app/guides/accessibility-testing) and great keyboard UX. -This command is _not_ chainable, and does not return a value. +Currently, the only key supported is `Tab`. -:::info +:::caution <strong>Supported Browsers:</strong> -This command is supported in chromium browsers, and Firefox versions beginning with -v135. Safari is not supported. This command will fail if executed in a browser that +This command is supported in chromium browsers and Firefox versions >= +v135. WebKit is not supported. This command will fail if executed in a browser that does not support it. ::: -:::caution - -<Icon name="exclamation-triangle" /> **Transient activation** - -By dispatching native keyboard events to the browser, this command will cause the browser to enter [Transient activation](https://developer.mozilla.org/en-US/docs/Glossary/Transient_activation) state. - -If your application prevents the default behavior of the `beforeunload` event, this may cause issues when navigating away from the current page. - -::: - ## Syntax ```javascript -cy.press(Cypress.Keyboard.Keys.TAB) -cy.press(Cypress.Keyboard.Keys.TAB, { - log: false, - timeout: 2000, -}) +cy.press(key) +cy.press(key, options) ``` ## Signature @@ -63,29 +50,25 @@ interface PressCommand { <Icon name="check-circle" color="green" /> **Correct Usage** ```javascript -it('moves focus to the next form element when the user presses tab', function () { - cy.visit('/my-form') - cy.get('input.first').focus() // focusing the first form element ensures that the application will receive the events - cy.press(Cypress.Keyboard.Keys.TAB) - cy.get('input.second').should('have.focus') -}) +cy.get('input.first').focus() +cy.press(Cypress.Keyboard.Keys.TAB) +cy.get('input.second').should('have.focus') ``` <Icon name="exclamation-triangle" color="red" /> **Incorrect Usage** ```javascript -it('moves focus to the next form element when the user presses tab', function () { - cy.visit('/my-form') - cy.press(Cypress.Keyboard.Keys.TAB) // the key event will be dispatched to the top frame, rather than your application - cy.get('input.second').should('have.focus') // the key events did not get dispatched to the application, so the focus did not shift to the second form element. -}) +cy.get('input.first').focus() +cy.press(Cypress.Keyboard.Keys.TAB) + // Errors because press yields null + .should('have.focus') ``` ### Arguments <Icon name="angle-right" /> **key _(String)_** -The key to press. The supported values are available on `Cypress.Keyboard.Keys`, and may change from time to time. It is recomended that you reference these values from `Cypress.Keyboard.Keys` rather than passing in a string. +The key to press. The supported values are available on `Cypress.Keyboard.Keys`, and may change from time to time. It's recomended that you reference these values from `Cypress.Keyboard.Keys` rather than passing in a string. ### Supported Keys @@ -95,13 +78,43 @@ The key to press. The supported values are available on `Cypress.Keyboard.Keys`, <Icon name="angle-right" /> **options _(Object)_** -The second `options` parameter is optional and standard for Cypress commands. It supports setting the timeout and/or whether to log the command: +Pass in an options object to change the default behavior of `.press()`. + +| Option | Default | Description | +| ---------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | +| `log` | `true` | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) | +| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `.click()` to resolve before [timing out](#Timeouts) | + +<HeaderYields /> + +- `cy.press()` yields `null`. + +## Examples + +### Move focus to the next element + +```js +it('moves focus to the next form element when pressing Tab', () => { + cy.visit('/my-form') + cy.get('input.first').focus() + cy.press(Cypress.Keyboard.Keys.TAB) + cy.get('input.second').should('have.focus') +}) +``` + +## Notes + +### Transient activation + +By dispatching native keyboard events to the browser, this command will cause the browser to enter [Transient activation](https://developer.mozilla.org/en-US/docs/Glossary/Transient_activation) state. + +If your application prevents the default behavior of the `beforeunload` event, this may cause issues when navigating away from the current page. ## History | Version | Changes | | ------------------------------------------ | --------------------------- | -| [14.2.2](/app/references/changelog#14-2-2) | Added the `press()` command | +| [14.2.2](/app/references/changelog#14-2-2) | Added the `.press()` command | ## See also From b6adcf9b55417cd3c5b6ed910dddfa5cd2046a56 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Mon, 31 Mar 2025 14:40:23 -0400 Subject: [PATCH 04/15] remove 'focus' note --- docs/api/commands/press.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index 4c1258dda1..e5721f04b5 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -12,7 +12,7 @@ componentSpecific: false Trigger native key events in your application to simulate keyboard interactions. -A `keydown`, `press`, and `keyup` event will be dispatched directly to the browser window. Note that your application must have focus to properly receive this event. It can be helpful to use `cy.focus()` to ensure focus on an element in your application before using this command. +A `keydown`, `press`, and `keyup` event will be dispatched directly to the browser window. Unlike `cy.type()`, which is best for typing character keys, `cy.press()` will dispatch real keyboard events rather than simulated ones. This command is especially useful when testing focus management and keyboard navigation patterns which are critical for [accessibility testing](/app/guides/accessibility-testing) and great keyboard UX. From cfb3ff9b51809c10bb670cc3168dbdd52146924b Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Mon, 31 Mar 2025 16:27:45 -0400 Subject: [PATCH 05/15] Document Keyboard.Keys --- docs/api/cypress-api/keyboard-api.mdx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/api/cypress-api/keyboard-api.mdx b/docs/api/cypress-api/keyboard-api.mdx index 8a8823e0c4..dd5b635e73 100644 --- a/docs/api/cypress-api/keyboard-api.mdx +++ b/docs/api/cypress-api/keyboard-api.mdx @@ -9,16 +9,29 @@ sidebar_position: 150 # Cypress.Keyboard -The Keyboard API allows you set the default values for how the +The Keyboard API allows you to access available `Keys` for use with [`cy.press()`](/api/commands/press) or to set the default values for how the [.type()](/api/commands/type) command is executed. ## Syntax ```javascript +Cypress.Keyboard.Keys(key) Cypress.Keyboard.defaults(options) ``` -### Arguments +### Keys Arguments + +<Icon name="angle-right" /> **key _(String)_** + +The key available for `cy.press()`. + +The following keys are supported: + +| Reference | Value | +| --------------------------- | ------- | +| `Cypress.Keyboard.Keys.TAB` | `"Tab"` | + +### defaults Arguments <Icon name="angle-right" /> **options _(Object)_** @@ -30,6 +43,13 @@ An object containing the following: ## Examples +### Press tab key + +```javascript +cy.press(Cypress.Keyboard.Keys.TAB) +cy.get('input.second').should('have.focus') +``` + ### Slow down typing by increasing the keystroke delay ```javascript @@ -72,9 +92,10 @@ describe('removes keystroke delay in all tests in this suite', { keystrokeDelay: it('types fast in the second input', () => { cy.get('input').eq(1).type('more fast typing') }) -})) +}) ``` ## See also +- [`cy.press()`](/api/commands/press) - [`.type()`](/api/commands/type) From 30724a30370020dd13b6925953b994996dc22eef Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Mon, 31 Mar 2025 16:30:43 -0400 Subject: [PATCH 06/15] update reference to command --- docs/api/commands/focus.mdx | 2 +- docs/api/commands/type.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/commands/focus.mdx b/docs/api/commands/focus.mdx index ea7c350832..bf1f67c959 100644 --- a/docs/api/commands/focus.mdx +++ b/docs/api/commands/focus.mdx @@ -159,5 +159,5 @@ the following: - [`.blur()`](/api/commands/blur) - [`.click()`](/api/commands/click) - [`cy.focused()`](/api/commands/focused) -- [`.press()`](/api/commands/press) +- [`cy.press()`](/api/commands/press) - [`.type()`](/api/commands/type) diff --git a/docs/api/commands/type.mdx b/docs/api/commands/type.mdx index 46e999f93e..97f7030c87 100644 --- a/docs/api/commands/type.mdx +++ b/docs/api/commands/type.mdx @@ -664,6 +664,6 @@ following: - [`.clear()`](/api/commands/clear) - [`.click()`](/api/commands/click) - [`.focus()`](/api/commands/focus) -- [`.press()`](/api/commands/press) +- [`cy.press()`](/api/commands/press) - [`.submit()`](/api/commands/submit) - [`Cypress.Keyboard`](/api/cypress-api/keyboard-api) From 5136ef952d45875fff94a427a78bd6efa19a9fa3 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Tue, 1 Apr 2025 09:16:10 -0400 Subject: [PATCH 07/15] Update example to be a little more real case --- docs/api/commands/press.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index e5721f04b5..a6366157bb 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -95,10 +95,10 @@ Pass in an options object to change the default behavior of `.press()`. ```js it('moves focus to the next form element when pressing Tab', () => { - cy.visit('/my-form') - cy.get('input.first').focus() + cy.visit('/my-login') + cy.get('input.email').type('username') cy.press(Cypress.Keyboard.Keys.TAB) - cy.get('input.second').should('have.focus') + cy.get('input.password').should('have.focus') }) ``` From 65cdc6cfa6603b4a9f162bdbec293d22168c5bc4 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Tue, 1 Apr 2025 09:19:18 -0400 Subject: [PATCH 08/15] Add another example of autocomplete with tab --- docs/api/commands/press.mdx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index a6366157bb..f9814a094f 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -91,7 +91,7 @@ Pass in an options object to change the default behavior of `.press()`. ## Examples -### Move focus to the next element +### Test focus order of tab ```js it('moves focus to the next form element when pressing Tab', () => { @@ -102,6 +102,16 @@ it('moves focus to the next form element when pressing Tab', () => { }) ``` +### Test autocomplete of search input with tab + +```js +it('autocompletes search input when pressing Tab', () => { + cy.get('[data-cy="search"]').type('cy') + cy.press(Cypress.Keyboard.Keys.TAB) + cy.get('[data-cy="search"]').should('have.value', 'cypress') +}) +``` + ## Notes ### Transient activation From bf6ec3dfe3ff1c20658c7a16b959c207d9e9adb1 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Tue, 1 Apr 2025 10:04:14 -0400 Subject: [PATCH 09/15] Add link to keyboard api page --- docs/api/commands/press.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index f9814a094f..676db0d329 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -68,7 +68,7 @@ cy.press(Cypress.Keyboard.Keys.TAB) <Icon name="angle-right" /> **key _(String)_** -The key to press. The supported values are available on `Cypress.Keyboard.Keys`, and may change from time to time. It's recomended that you reference these values from `Cypress.Keyboard.Keys` rather than passing in a string. +The key to press. The supported values are available on [`Cypress.Keyboard.Keys`](/api/cypress-api/keyboard-api), and may change from time to time. It's recomended that you reference these values from `Cypress.Keyboard.Keys` rather than passing in a string. ### Supported Keys From 86024bca672f81f07122d0b8476325874d0693fb Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Tue, 1 Apr 2025 10:21:07 -0400 Subject: [PATCH 10/15] Fix version number for introduction --- docs/api/commands/press.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index 676db0d329..3207e254f2 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -124,7 +124,7 @@ If your application prevents the default behavior of the `beforeunload` event, t | Version | Changes | | ------------------------------------------ | --------------------------- | -| [14.2.2](/app/references/changelog#14-2-2) | Added the `.press()` command | +| [14.3.0](/app/references/changelog) | Added the `.press()` command | ## See also From 02f0e6cf25ce2170458df47d0400a1a1f1b83b56 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Tue, 1 Apr 2025 10:23:14 -0400 Subject: [PATCH 11/15] Fix broken link --- docs/api/commands/press.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index 3207e254f2..f28e52d15d 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -131,5 +131,4 @@ If your application prevents the default behavior of the `beforeunload` event, t - [`.focus()`](/api/commands/focus) - [`.focused()`](/api/commands/focused) - [`.type()`](/api/commands/type) -- [`.focused()`](/api/) - [`Cypress.Keyboard`](/api/cypress-api/keyboard-api) From 8b490d729bbc7340313cc68a89e4acb5f3631c75 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Tue, 1 Apr 2025 10:23:31 -0400 Subject: [PATCH 12/15] alphabetize see also --- docs/api/commands/press.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index f28e52d15d..db288ef908 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -128,7 +128,7 @@ If your application prevents the default behavior of the `beforeunload` event, t ## See also +- [`Cypress.Keyboard`](/api/cypress-api/keyboard-api) - [`.focus()`](/api/commands/focus) - [`.focused()`](/api/commands/focused) - [`.type()`](/api/commands/type) -- [`Cypress.Keyboard`](/api/cypress-api/keyboard-api) From ee7638ac0b8e3e1814935276062386d6247d806f Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Thu, 3 Apr 2025 10:39:41 -0400 Subject: [PATCH 13/15] Update package.json Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index ba38c29ce0..51219dfc5d 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,5 @@ "last 1 firefox version", "last 1 safari version" ] - }, - "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" + } } From 1f3240eb35322bce9fcde64bf316326bf5e09e06 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Mon, 7 Apr 2025 10:10:56 -0400 Subject: [PATCH 14/15] Fix broken link --- docs/api/commands/press.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index db288ef908..e46e134f7e 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -83,7 +83,7 @@ Pass in an options object to change the default behavior of `.press()`. | Option | Default | Description | | ---------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `log` | `true` | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) | -| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `.click()` to resolve before [timing out](#Timeouts) | +| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `cy.press()` to resolve before timing out | <HeaderYields /> From af05f3c5f2c9e3e03adea0e9d153e1c528b2afb4 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane <jennifer@cypress.io> Date: Mon, 7 Apr 2025 10:20:24 -0400 Subject: [PATCH 15/15] lint --- docs/api/commands/press.mdx | 20 ++++++++--------- docs/api/cypress-api/keyboard-api.mdx | 32 +++++++++++++++++---------- docs/api/table-of-contents.mdx | 2 +- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/docs/api/commands/press.mdx b/docs/api/commands/press.mdx index e46e134f7e..f0bef379fe 100644 --- a/docs/api/commands/press.mdx +++ b/docs/api/commands/press.mdx @@ -21,9 +21,9 @@ Currently, the only key supported is `Tab`. :::caution <strong>Supported Browsers:</strong> -This command is supported in chromium browsers and Firefox versions >= -v135. WebKit is not supported. This command will fail if executed in a browser that -does not support it. +This command is supported in chromium browsers and Firefox versions >= v135. WebKit +is not supported. This command will fail if executed in a browser that does not support +it. ::: @@ -61,7 +61,7 @@ cy.get('input.second').should('have.focus') cy.get('input.first').focus() cy.press(Cypress.Keyboard.Keys.TAB) // Errors because press yields null - .should('have.focus') + .should('have.focus') ``` ### Arguments @@ -80,10 +80,10 @@ The key to press. The supported values are available on [`Cypress.Keyboard.Keys` Pass in an options object to change the default behavior of `.press()`. -| Option | Default | Description | -| ---------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -| `log` | `true` | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) | -| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `cy.press()` to resolve before timing out | +| Option | Default | Description | +| --------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- | +| `log` | `true` | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) | +| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `cy.press()` to resolve before timing out | <HeaderYields /> @@ -122,8 +122,8 @@ If your application prevents the default behavior of the `beforeunload` event, t ## History -| Version | Changes | -| ------------------------------------------ | --------------------------- | +| Version | Changes | +| ----------------------------------- | ---------------------------- | | [14.3.0](/app/references/changelog) | Added the `.press()` command | ## See also diff --git a/docs/api/cypress-api/keyboard-api.mdx b/docs/api/cypress-api/keyboard-api.mdx index dd5b635e73..e01f3ab19f 100644 --- a/docs/api/cypress-api/keyboard-api.mdx +++ b/docs/api/cypress-api/keyboard-api.mdx @@ -79,20 +79,28 @@ The keystroke delay can also be set via which can be useful when setting it for a single test or a subset of tests. ```javascript -it('removes keystroke delay for all typing in this test', { keystrokeDelay: 0 }, () => { - cy.get('input').eq(0).type('fast typing') - cy.get('input').eq(1).type('more fast typing') -}) - -describe('removes keystroke delay in all tests in this suite', { keystrokeDelay: 0 }, () => { - it('types fast in the first input', () => { +it( + 'removes keystroke delay for all typing in this test', + { keystrokeDelay: 0 }, + () => { cy.get('input').eq(0).type('fast typing') - }) - - it('types fast in the second input', () => { cy.get('input').eq(1).type('more fast typing') - }) -}) + } +) + +describe( + 'removes keystroke delay in all tests in this suite', + { keystrokeDelay: 0 }, + () => { + it('types fast in the first input', () => { + cy.get('input').eq(0).type('fast typing') + }) + + it('types fast in the second input', () => { + cy.get('input').eq(1).type('more fast typing') + }) + } +) ``` ## See also diff --git a/docs/api/table-of-contents.mdx b/docs/api/table-of-contents.mdx index 20446f398d..01c2a7f43f 100644 --- a/docs/api/table-of-contents.mdx +++ b/docs/api/table-of-contents.mdx @@ -139,7 +139,7 @@ Cypress has a variety of additional commands to help write tests. | [`.mount()`](/api/commands/mount) | Mount a component for Cypress Component Testing. | | [`.origin()`](/api/commands/origin) | Visit multiple domains of different origin in a single test. | | [`.pause()`](/api/commands/pause) | Pause test execution, allowing interaction with the application under test before resuming. | -| [`.press()`](/api/commands/press) | Trigger native key events in your application to simulate real user keyboard interactions. | +| [`.press()`](/api/commands/press) | Trigger native key events in your application to simulate real user keyboard interactions. | | [`.readFile()`](/api/commands/readfile) | Read a file from disk. | | [`.reload()`](/api/commands/reload) | Reload the page. | | [`.request()`](/api/commands/request) | Make an HTTP request. |