Skip to content
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

Need a "rightclick" command #53

Closed
jennifer-shehane opened this issue Jul 15, 2015 · 20 comments · Fixed by #3030
Closed

Need a "rightclick" command #53

jennifer-shehane opened this issue Jul 15, 2015 · 20 comments · Fixed by #3030
Assignees
Labels
pkg/driver This is due to an issue in the packages/driver directory topic: rightclick 🖱 type: feature New feature that does not currently exist

Comments

@jennifer-shehane
Copy link
Member

I need the ability to right click an element within Cypress so that it triggers the contextmenu event and all that entails.

@jennifer-shehane jennifer-shehane added the type: feature New feature that does not currently exist label Jul 15, 2015
@oliver3
Copy link

oliver3 commented Mar 14, 2017

I would also like to have this functionality.

@jennifer-shehane jennifer-shehane added the pkg/driver This is due to an issue in the packages/driver directory label Mar 14, 2017
@oliver3
Copy link

oliver3 commented Mar 21, 2017

I've created my own custom command which is working for me:

Cypress.addChildCommand('contextmenu', ($subject) => {
  const log = Cypress.Log.command({
    name: 'CONTEXTMENU'
  })

  const e = document.createEvent('HTMLEvents');
  e.initEvent('contextmenu', true, false);
  $subject[0].dispatchEvent(e);

  log.snapshot().end()
})

Usage:
cy.get('.some-item').contextmenu()

@jennifer-shehane
Copy link
Member Author

Thanks for sharing @oliver3. We will soon be releasing cy.trigger() which will also help with supporting custom functionality like right-click, so be on the lookout for that! #406

@brian-mann
Copy link
Member

brian-mann commented Nov 4, 2017

With 0.20.0 it's possible to simply use cy.trigger() to trigger the contextmenu event.

cy.get('button').trigger('contextmenu', options)

@jennifer-shehane jennifer-shehane added the stage: proposal 💡 No work has been done of this issue label Dec 12, 2017
@tnrich
Copy link
Contributor

tnrich commented Dec 13, 2018

I still would vote for a right click helper :)

@jennifer-shehane
Copy link
Member Author

The delivery of a specific .rightclick() command is part of the considerations while working on the Native Events release. You can see the progress being made here: #2956

@TheSerg
Copy link

TheSerg commented Jan 22, 2019

Workaround

Example of triggering contextmenu event:

cy.get('#nav').first().trigger('contextmenu')

Example of right clicking on an element using jQuery

cy.get('#nav').first().invoke('trigger', 'contextmenu')

@indrajitbnikam
Copy link

Hi all,
how can I click one of the button located inside of context menu?

Thanks in advance

@kuceb
Copy link
Contributor

kuceb commented Mar 18, 2019

@indrajitbnikam if you're talking about the native context menu, then you cannot, since it's not rendered to the DOM, it's native code.

@indrajitbnikam
Copy link

indrajitbnikam commented Mar 19, 2019

@bkucera No I'm not talking about browser's native context menu. I'm talking about context menu from our application.
My code looks like this,

cy.contains(val).first().click().trigger('contextmenu');
cy.get('si-context-menu ul').contains('li', 'Delete').first().click();

It is visible in DOM and CSS selector that I'm using points towards the same element but I'm not able to click it.
As you can see,
image
it indicates that elements are not visible.

@indrajitbnikam
Copy link

Hi Everyone it worked, Problem was that it was not visible unless I am moving my mouse into context menu.
I addressed the problem just by adding .trigger('mouseenter') before click.
Now my code looks like this,

cy.contains(val).first().click().trigger('contextmenu');
cy.get('si-context-menu ul').contains('li', 'Delete').first().trigger('mouseenter').click();

@loveqseven
Copy link

loveqseven commented Jul 26, 2019

Is right click available in 3.4.0?

@jennifer-shehane
Copy link
Member Author

@loveqseven The issue will be closed and marked with a release number when it is released. If an issue is still open, it is not released.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: proposal 💡 No work has been done of this issue stage: needs review The PR code is done & tested, needs review labels Aug 8, 2019
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Sep 6, 2019
@loveqseven
Copy link

I tried suggestions from @oliver3 and @brian-mann, they both work for some url e.g. http://teselagen.github.io/openVectorEditor/#/Editor
However, for triggering context menu on one random point on google map it does not work, any idea, what locator I can use to trigger the context menu on some random point on google map like this? thanks
image

@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs review The PR code is done & tested, needs review labels Sep 25, 2019
@kuceb kuceb self-assigned this Sep 26, 2019
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels Sep 30, 2019
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Oct 7, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Oct 11, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 11, 2019

The code for this is done in cypress-io/cypress#3030, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 23, 2019

Released in 3.5.0.

@ronaiza-cardoso
Copy link

@loveqseven are you able to use the rightclick() command on the map? I'm not. :

@ben-x-dev
Copy link

still can't use rightclick to replace trigger('contextmenu'), it's always giving me this error:

Uncaught TypeError: Cannot read property 'id' of undefined

@kuceb
Copy link
Contributor

kuceb commented Nov 12, 2019

@nbcp could you open up an issue with some screenshots / reproducible example?

@ben-x-dev
Copy link

I wrote it up in #5698

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Jan 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg/driver This is due to an issue in the packages/driver directory topic: rightclick 🖱 type: feature New feature that does not currently exist
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants