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

Click function does not respect coordinates (x, y) if they are 0 #7319

Closed
panzarino opened this issue May 13, 2020 · 3 comments · Fixed by #7339
Closed

Click function does not respect coordinates (x, y) if they are 0 #7319

panzarino opened this issue May 13, 2020 · 3 comments · Fixed by #7339

Comments

@panzarino
Copy link
Contributor

panzarino commented May 13, 2020

Current behavior:

cy.click will not respect either coordinate option if it is passed as 0. This is because a truthy comparison is used to set the default option, when it should really check if it is a finite number.

This issue is most likely present on right click and double click as well.

Desired behavior:

x and y parameters can be 0 and the function will behave as it does for all other number values (and click the top left of the element).

Test code to reproduce

it('can specify x and/or y to be 0', () => {
  const $btn = $('<button id="click-button">clicking button</button>')
  .prependTo(cy.$$('body'))

  const position = $btn.offset()

  cy.on('log:changed', (log, attr) => {
    if (log.name === 'click' && attr._emittedAttrs.coords) {
      const args = attr._emittedAttrs.message.split(', ').map((i) => parseInt(i))
      const coords = attr._emittedAttrs.coords

      expect(coords.x).to.equal(coords.left)
      expect(coords.y).to.equal(coords.top)
      expect(coords.x).to.equal(position.left + args[0])
      expect(coords.y).to.equal(position.top + args[1])
    }
  })

  cy.get('#click-button').click(2, 2)
  cy.get('#click-button').click(0, 0)
  cy.get('#click-button').click(0, 2)
  cy.get('#click-button').click(2, 0)
})
@panzarino panzarino self-assigned this May 13, 2020
@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] stage: needs review The PR code is done & tested, needs review and removed stage: work in progress There is an open PR for this issue [WIP] labels May 13, 2020
@jennifer-shehane
Copy link
Member

I was a little unsure what the behavior was before from the description, but basically it would click 'center' which is the default position and ignore all coords. Example:

it('click 0 x coord', () => {
  cy.visit('https://example.cypress.io//commands/actions')
  cy.get('#action-canvas').click(0, 20)
});

it('click 0 y coord', () => {
  cy.visit('https://example.cypress.io//commands/actions')
  cy.get('#action-canvas').click(20, 0)
});

it('click 0 x 0  coord', () => {
  cy.visit('https://example.cypress.io//commands/actions')
  cy.get('#action-canvas').click(0, 0)
});

Screen Shot 2020-05-14 at 1 59 31 PM

@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: needs review The PR code is done & tested, needs review labels May 14, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 14, 2020

The code for this is done in cypress-io/cypress#7339, 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 May 20, 2020

Released in 4.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.6.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label May 20, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants