-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: release 14.3.0 documentation #6144
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
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a83ffa7
feat: documentation for the press() command (#6135)
cacieprins 36edf4d
chore: add 14.3.0 changelog to documentation
AtofStryker 1c4cfee
Update docs/app/guides/accessibility-testing.mdx
jennifer-shehane 0e4700a
Update docs/app/references/changelog.mdx
jennifer-shehane bb56d46
Merge branch 'main' into chore/release_14_3_0
jennifer-shehane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
--- | ||
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 | ||
--- | ||
|
||
<ProductHeading product="app" /> | ||
|
||
# press | ||
|
||
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. | ||
|
||
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. | ||
|
||
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. | ||
|
||
::: | ||
|
||
## Syntax | ||
|
||
```javascript | ||
cy.press(key) | ||
cy.press(key, options) | ||
``` | ||
|
||
## Signature | ||
|
||
```typescript | ||
interface PressCommand { | ||
( | ||
key: KeyPressSupportedKeys, | ||
options?: Partial<Cypress.Loggable> & Partial<Cypress.Timeoutable> | ||
): void | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
<Icon name="check-circle" color="green" /> **Correct Usage** | ||
|
||
```javascript | ||
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 | ||
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`](/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 | ||
|
||
| Reference | Value | | ||
| --------------------------- | ------- | | ||
| `Cypress.Keyboard.Keys.TAB` | `"Tab"` | | ||
|
||
<Icon name="angle-right" /> **options _(Object)_** | ||
|
||
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 | | ||
|
||
<HeaderYields /> | ||
|
||
- `cy.press()` yields `null`. | ||
|
||
## Examples | ||
|
||
### Test focus order of tab | ||
|
||
```js | ||
it('moves focus to the next form element when pressing Tab', () => { | ||
cy.visit('/my-login') | ||
cy.get('input.email').type('username') | ||
cy.press(Cypress.Keyboard.Keys.TAB) | ||
cy.get('input.password').should('have.focus') | ||
}) | ||
``` | ||
|
||
### 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 | ||
|
||
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.3.0](/app/references/changelog) | Added the `.press()` command | | ||
|
||
## See also | ||
|
||
- [`Cypress.Keyboard`](/api/cypress-api/keyboard-api) | ||
- [`.focus()`](/api/commands/focus) | ||
- [`.focused()`](/api/commands/focused) | ||
- [`.type()`](/api/commands/type) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.