-
Notifications
You must be signed in to change notification settings - Fork 1.1k
.rightclick command #2174
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
.rightclick command #2174
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c26b41
Add rightclick doc
jennifer-shehane c1804f8
Update the contributing docs to be clearer about how to add a new doc…
jennifer-shehane 990cc77
Update source/api/commands/rightclick.md
jennifer-shehane 31e4738
Update id of DOM element to open content menu to make more sense
jennifer-shehane e7f224b
Add some more places where rightclick should be mentioned
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
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,199 @@ | ||
| --- | ||
| title: rightclick | ||
| --- | ||
|
|
||
| Right click a DOM element. | ||
|
|
||
| {% note warning %} | ||
| `.rightclick()` will not open context menus native to the browser. `.rightclick()` should be used to test the behavior of an application where a user would right click a mouse. | ||
| {% endnote %} | ||
|
|
||
| # Syntax | ||
|
|
||
| ```javascript | ||
| .rightclick() | ||
| .rightclick(options) | ||
| .rightclick(position) | ||
| .rightclick(position, options) | ||
| .rightclick(x, y) | ||
| .rightclick(x, y, options) | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| **{% fa fa-check-circle green %} Correct Usage** | ||
|
|
||
| ```javascript | ||
| cy.get('.menu').rightclick() // Right click on .menu | ||
| cy.focused().rightclick() // Right click on el with focus | ||
| cy.contains('Today').rightclick() // Right click on first el containing 'Today' | ||
| ``` | ||
|
|
||
| **{% fa fa-exclamation-triangle red %} Incorrect Usage** | ||
|
|
||
| ```javascript | ||
| cy.rightclick('button') // Errors, cannot be chained off 'cy' | ||
| cy.window().rightclick() // Errors, 'window' does not yield DOM element | ||
| ``` | ||
|
|
||
| ## Arguments | ||
|
|
||
| **{% fa fa-angle-right %} position** ***(String)*** | ||
|
|
||
| The position where the right click should be issued. The `center` position is the default position. Valid positions are `topLeft`, `top`, `topRight`, `left`, `center`, `right`, `bottomLeft`, `bottom`, and `bottomRight`. | ||
|
|
||
| {% imgTag "/img/api/coordinates-diagram.jpg" "cypress-command-positions-diagram" %} | ||
|
|
||
| **{% fa fa-angle-right %} x** ***(Number)*** | ||
|
|
||
| The distance in pixels from the element's left to issue the right click. | ||
|
|
||
| **{% fa fa-angle-right %} y** ***(Number)*** | ||
|
|
||
| The distance in pixels from the element's top to issue the right click. | ||
|
|
||
| **{% fa fa-angle-right %} options** ***(Object)*** | ||
|
|
||
| Pass in an options object to change the default behavior of `.rightclick()`. | ||
|
|
||
| Option | Default | Description | ||
| --- | --- | --- | ||
| `log` | `true` | {% usage_options log %} | ||
| `force` | `false` | {% usage_options force rightclick %} | ||
| `multiple` | `false` | {% usage_options multiple rightclick %} | ||
| `timeout` | {% url `defaultCommandTimeout` configuration#Timeouts %} | {% usage_options timeout .rightclick %} | ||
|
|
||
| ## Yields {% helper_icon yields %} | ||
|
|
||
| {% yields same_subject .rightclick %} | ||
|
|
||
| # Examples | ||
|
|
||
| ## No Args | ||
|
|
||
| ### Right click the menu | ||
|
|
||
| ```javascript | ||
| cy.get('#context-menu').rightclick() | ||
jennifer-shehane marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Position | ||
|
|
||
| ### Specify a corner of the element to right click | ||
|
|
||
| Right click the top right corner of the DOM element. | ||
|
|
||
| ```javascript | ||
| cy.get('#context-menu').rightclick('topRight') | ||
| ``` | ||
|
|
||
| ## Coordinates | ||
|
|
||
| ### Specify explicit coordinates relative to the top left corner | ||
|
|
||
| The right click below will be issued inside of the element (15px from the left and 40px from the top). | ||
|
|
||
| ```javascript | ||
| cy.get('#context-menu').rightclick(15, 40) | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| ### Force a right click regardless of its actionable state | ||
|
|
||
| Forcing a right click overrides the {% url 'actionable checks' interacting-with-elements#Forcing %} Cypress applies and will automatically fire the events. | ||
|
|
||
| ```javascript | ||
| cy.get('#context-menu').rightclick({ force: true }) | ||
| ``` | ||
|
|
||
| ### Force a right click with position argument | ||
|
|
||
| ```javascript | ||
| cy.get('#context-menu').rightclick('bottomLeft', { force: true }) | ||
| ``` | ||
|
|
||
| ### Force a right click with relative coordinates | ||
|
|
||
| ```javascript | ||
| cy.get('#context-menu').rightclick(5, 60, { force: true }) | ||
| ``` | ||
|
|
||
| ### Right click all buttons found on the page | ||
|
|
||
| By default, Cypress will error if you're trying to right click multiple elements. By passing `{ multiple: true }` Cypress will iteratively apply the right click to each element and will also log to the {% url 'Command Log' test-runner#Command-Log %} multiple times. | ||
|
|
||
| ```javascript | ||
| cy.get('.context-menu').rightclick({ multiple: true }) | ||
| ``` | ||
|
|
||
| ## Right click with key combinations | ||
|
|
||
| The `.rightclick()` command may also be fired with key modifiers in combination with the {% url "`.type()`" type %} command in order to simulate character sequences while right clicking, such as `ALT + rightclick`. In order to keep the modifier key active, `{release: false}` should be passed to the options of the {% url "`.type()`" type %} command. | ||
|
|
||
| The following modifiers can be combined with `.rightclick()`. | ||
|
|
||
| Sequence | Notes | ||
| --- | --- | ||
| `{alt}` | Activates the `altKey` modifier. Aliases: `{option}` | ||
| `{ctrl}` | Activates the `ctrlKey` modifier. Aliases: `{control}` | ||
| `{meta}` | Activates the `metaKey` modifier. Aliases: `{command}`, `{cmd}` | ||
| `{shift}` | Activates the `shiftKey` modifier. | ||
|
|
||
| ### Command right click | ||
|
|
||
| ```js | ||
| // execute a CMD + right click on the .menu-item | ||
| // { release: false } is necessary so that | ||
| // CMD will not be released after the type command | ||
| cy.get('body').type('{cmd}', { release: false }) | ||
| cy.get('.menu-item').rightclick() | ||
| ``` | ||
|
|
||
| # Notes | ||
|
|
||
| ## Actionability | ||
|
|
||
| ### The element must first reach actionability | ||
|
|
||
| `.rightclick()` is an "action command" that follows all the rules {% url 'defined here' interacting-with-elements %}. | ||
|
|
||
| # Rules | ||
|
|
||
| ## Requirements {% helper_icon requirements %} | ||
|
|
||
| {% requirements dom .rightclick %} | ||
|
|
||
| ## Assertions {% helper_icon assertions %} | ||
|
|
||
| {% assertions actions .rightclick %} | ||
|
|
||
| ## Timeouts {% helper_icon timeout %} | ||
|
|
||
| {% timeouts actions .rightclick %} | ||
|
|
||
| # Command Log | ||
|
|
||
| ***Right click the button in the form that has text "Create User"*** | ||
|
|
||
| ```javascript | ||
| cy.get('form').find('button').contains('Create User').rightclick() | ||
| ``` | ||
|
|
||
| The commands above will display in the Command Log as: | ||
|
|
||
| {% imgTag /img/api/rightclick/rightclick-dom-element-in-command-log.png "Command log for right click" %} | ||
|
|
||
| When clicking on `rightclick` within the command log, the console outputs the following: | ||
|
|
||
| {% imgTag /img/api/rightclick/rightclick-console-log-with-mouse-events.png "console.log for right click" %} | ||
|
|
||
| {% history %} | ||
| {% url "3.5.0" changelog#3-5-0 %} | `.rightclick()` command added | ||
| {% endhistory %} | ||
|
|
||
| # See also | ||
|
|
||
| - {% url `.click()` click %} | ||
| - {% url `.dblclick()` dblclick %} | ||
| - {% url `.trigger()` trigger %} | ||
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
Binary file added
BIN
+269 KB
.../cypress/source/img/api/rightclick/rightclick-console-log-with-mouse-events.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.4 KB
themes/cypress/source/img/api/rightclick/rightclick-dom-element-in-command-log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.