-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
feat: cy.press() #31398
feat: cy.press() #31398
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces the driver implementation for cy.press(), enabling simulated keypress events in Chromium and Firefox (v>135) browsers.
- Implements a new helper (isSupportedKey) in the server automation commands to validate supported keys.
- Adds a new cy.press() command along with comprehensive unit and end-to-end tests.
- Updates error messages, vitest configuration, and command registration to support the new functionality.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
packages/server/lib/automation/commands/key_press.ts | Adds isSupportedKey helper to validate supported keys |
packages/driver/vitest.config.mjs | Adds setupFiles configuration for test mocks |
packages/driver/test/unit/cy/commands/actions/press.spec.ts | Introduces unit tests for the new press command |
packages/driver/test/setup/setupMocks.ts | Provides required mocks for source map utilities |
packages/driver/src/cypress/error_messages.ts | Introduces error messages for press command issues |
packages/driver/src/cypress/commands.ts | Adds type annotations for commands related to press |
packages/driver/src/cy/commands/actions/press.ts | Implements the cy.press() command logic |
packages/driver/src/cy/commands/actions/index.ts | Registers the new press command |
packages/driver/cypress/e2e/commands/actions/press.cy.ts | Provides an end-to-end test for cy.press() |
Comments suppressed due to low confidence (1)
packages/server/lib/automation/commands/key_press.ts:24
- BIDI_VALUE is used here but is not defined or imported in the diff. Please ensure that BIDI_VALUE is properly declared or imported to avoid runtime errors.
return CDP_KEYCODE[key] && BIDI_VALUE[key]
cli/types/cypress.d.ts
Outdated
* cy.press(Cypress.Keyboard.Keys.TAB) // dispatches a keydown and press event to the browser, followed by a keyup event. | ||
* @see https://on.cypress.io/press | ||
*/ | ||
press(key: 'Tab' /* todo */, options?: Partial<Loggable & Timeoutable>): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a direct reference to Keys.TAB? or the Key's interface?
cypress
|
Project |
cypress
|
Branch Review |
cacie/feat/cy-press-command
|
Run status |
|
Run duration | 18m 50s |
Commit |
|
Committer | Jennifer Shehane |
View all properties for this run ↗︎ |
Test results | |
---|---|
|
1
|
|
10
|
|
1232
|
|
0
|
|
32139
|
View all changes introduced in this branch ↗︎ |
UI Coverage
46.46%
|
|
---|---|
|
184
|
|
164
|
Accessibility
92.63%
|
|
---|---|
|
3 critical
8 serious
2 moderate
2 minor
|
|
878
|
Tests for review
cypress/e2e/commands/actions/press.cy.ts • 1 failed test • 5x-driver-firefox
"no-single-declare-module": false | ||
"no-single-declare-module": false, | ||
// This is detecting necessary qualifiers as unnecessary | ||
"no-unnecessary-qualifier": false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the reason we are doing this? is it related to the keys only having one value in it, i.e "tab"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was getting thrown by L#1758 - tslint thinks the Cypress
reference here is the namespace, but it's the interface Cypress
within the namespace.
(no-unnecessary-qualifier
throws when you reference the namespace from within the namespace - generally you don't need to and shouldn't, because you're in scope with the namespace. But we have an interface named the same as the namespace, and tslint gets confused because of it)
}) | ||
}) | ||
|
||
describe('when there are invalid execution contexts associated with the top frame', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a weird question but what defines an invalid execution context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An execution context that is no longer available; electron doesn't always emit the execution context removed event when it removes an execution context, so we need to loop through and determine which execution context associated with top is actually available.
@@ -162,6 +162,8 @@ describe('lib/browsers/firefox', () => { | |||
context: mockContextId, | |||
url: 'next-spec-url', | |||
}) | |||
|
|||
expect(this.automation.use).to.have.been.calledWith(bidiAutomationClient.automationMiddleware) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably need a test to make sure this gets called on the initial context initialization and not just connectToNewSpecBiDi
* dependency: upgrade mocha to 7.2.0 (#31423) * dependency: upgrade mocha to 7.2.0 * changelog entry * remove the it.only from the mocha patch changelog that is triggering our stop-only check from passing * skip patches folder with stop-only check * remove extra bracket * Update protocol_spec to reflect new mocha line number for error stack trace * chore: updating v8 snapshot cache (#31424) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: updating v8 snapshot cache (#31425) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: updating v8 snapshot cache (#31426) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: migrates plugin system test to a v3 extension (#31434) * chore: Update Chrome (stable) to 135.0.7049.52 (#31428) * chore: Update Chrome (stable) to 135.0.7049.52 * empty commit --------- Co-authored-by: cypress-bot[bot] <41898282+cypress-bot[bot]@users.noreply.github.com> Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Cacie Prins <[email protected]> * chore: bump Firefox to 137 (#31431) * chore: bump Firefox to 137 * use 137 version? weird. * just kidding, major version only has 1 zero after it................ * dependency: update server to mocha 7.2.0 (#31432) * dependency: update server to mocha 7.2.0 * Add PR to changelog * chore: updating v8 snapshot cache (#31437) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: updating v8 snapshot cache (#31438) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: updating v8 snapshot cache (#31439) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: Update Chrome (beta) to 136.0.7103.17 (#31448) * chore: Update Chrome (beta) to 136.0.7103.17 * empty commit --------- Co-authored-by: cypress-bot[bot] <41898282+cypress-bot[bot]@users.noreply.github.com> Co-authored-by: Jennifer Shehane <[email protected]> * refactor: lifts toPosix to its own file, removes circular dependency between stack_utils and source_map_utils (#30983) * refactor: lifts toPosix to remove circular dependency between stack_utils and source_map_utils * camelCase to snake_case * rm duplicated file * internal: (studio) make the protocol database accessible to studio (#31443) * internal: (studio) make the protocol database accessible to studio * PR comment * chore(deps): update dependency patch-package to v8 (#31451) * chore(deps): update dependency patch-package to v8 * empty commit * add types to handle json-stable-stringify dep change --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Jennifer Shehane <[email protected]> * chore: fix deprecation warnings and refactor react reporter to use functional components and hooks (#31284) * chore: fix deprecation warnings and refactor react reporter to use functional components with hooks * chore: update code to reflect feedback from code review * fix issues with scrollIntoView() on updated component and refactor isOpen logic in collapsible to not attempt to sync state * fix issues with tests after refactor * see if event registration fixes windows flake * chore: update snap-shot-core patch package file to match version (#31449) * chore: update snap-shot-core patch package file to match version * update circle cache * experiment with removing .md from yarnclean * add .md back to yarnclean * bust circle cache * remove .md files being cleaned from yarn to get around patch-package issue * print size of cache * try out the size of the .md * remove md from yarnclean * UPdate to version without removal of markdown files * chore: updating v8 snapshot cache (#31460) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: updating v8 snapshot cache (#31462) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * chore: updating v8 snapshot cache (#31461) Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> * feat: cy.press() (#31398) * wip - cy.press() command * cy command for dispatching key press/down/up events * unit tests and failure cases for cy.press() * Cypress.Keyboard.Keys definition; fix command log message * add keys to the internal keyboard type * auto-focus in cdp * ensure aut iframe is focused before dispatching key events in bidi browsers * update tests for cdp focus * fixed tests for bidi * lint * fix type ref in .d.ts * linting * skip press() driver test in ff below v135 * try all contexts for frame before failing due to missing/invalid context id * ensure error is error before accessing props * skip press driver test in webkit * changelog * debug automation middleware invocation for firefox flake * debug * cache update * use bidi automation middleware from connectToNewSpec rather than constructor * more comprehensive logging * debug socket base, additional debug in automation * install firefox automation middleware on setup as well as connectToNewSpec * unit tests for firefox-utils * proper calledWith --------- Co-authored-by: Jennifer Shehane <[email protected]> * docs: update contributing requirements for corepack (#31463) * chore: remove `du` check (#31465) * chore: use different args for `du` in win * rm du command for build * chore: release 14.3.0 (#31467) --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com> Co-authored-by: Cacie Prins <[email protected]> Co-authored-by: cypress-bot[bot] <41898282+cypress-bot[bot]@users.noreply.github.com> Co-authored-by: Ryan Manuel <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Mike McCready <[email protected]>
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Additional details
Driver implementation for
cy.press()
. Supported in chromium browsers and firefox versions >135.Steps to test
How has the user experience changed?
See docs: cypress-io/cypress-documentation#6135
PR Tasks
cypress-documentation
? feat: documentation for the press() command cypress-documentation#6135type definitions
?