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

cy.click() doesn’t select element in custom dropdown component #5805

Closed
Sharan-ram opened this issue Nov 27, 2019 · 16 comments
Closed

cy.click() doesn’t select element in custom dropdown component #5805

Sharan-ram opened this issue Nov 27, 2019 · 16 comments
Labels
pkg/driver This is due to an issue in the packages/driver directory stage: ready for work The issue is reproducible and in scope stale no activity on this issue for a long period topic: cy.click 🖱 topic: native events type: regression A bug that didn't appear until a specific Cy version release v3.5.0 🐛 Issue present since 3.5.0

Comments

@Sharan-ram
Copy link

Sharan-ram commented Nov 27, 2019

Current behavior:

With the update to 3.5.0, Cypress doesnt seem to select the right MenuItem from the Material ui Popper. The cy.click() is applied to the right element but the actual element clicked is wrong. I have made a sample demo app reproducing the issue and a screenshot has been attached below:

Screenshot from 2019-11-27 18-57-04

Desired Behaviour:

cy.click() should be applied to the right element

Steps to reproduce:

Here is a sample repo which reproduces the issue. Run npm run cypress:open, select app.test.js file, you can see on the console that applied to is different from actual element clicked.

Versions

Cypress 3.5.0, reproducible even in v3.6.1
Browser Chrome

@sepehr500
Copy link

I have the same issue.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Jan 2, 2020

The actual assertion should be checking the value, as this will fail whether the component selects properly or not, so change your last assertion to:

cy.get("[name=foods]").should("have.value", "Beef");

Regardless, this is a regression that was introduced in 3.5.0 and has not been fixed as of 3.8.1.

Repro

Run this repo: https://github.com/Sharan-ram/cypress-bug-demo and change last assertion to

cy.get("[name=foods]").should("have.value", "Beef");

3.4.1

Screen Shot 2020-01-02 at 2 49 06 PM

3.5.0

All of the mouse click events seem to be happening on html.

Screen Shot 2020-01-02 at 2 54 22 PM

3.8.1

3.8.1 indicates the exact same mouse event behavior

Screen Shot 2020-01-02 at 2 56 09 PM

Workaround

Downgrade to 3.4.1 of Cypress.

@jennifer-shehane jennifer-shehane added the type: regression A bug that didn't appear until a specific Cy version release label Jan 2, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jan 2, 2020
@jennifer-shehane jennifer-shehane added v3.5.0 🐛 Issue present since 3.5.0 topic: cy.click 🖱 pkg/driver This is due to an issue in the packages/driver directory stage: ready for work The issue is reproducible and in scope and removed stage: ready for work The issue is reproducible and in scope labels Jan 2, 2020
@vramana
Copy link

vramana commented Jan 2, 2020

@jennifer-shehane I did some digging into this issue yesterday.

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/actions/click.js#L157

mousemove event on the targetElement causes it to recompute it's position and it looks something like this.

img So for the rest of the command the popover just stays towards the left we click on html element.

I did this testing with master branch. I have not checked what happens in 3.4.1

@jennifer-shehane
Copy link
Member

Ran across this other issue with material-ui today, thought I would comment in case it sheds some light. #5826 (comment)

@stevenvachon
Copy link

stevenvachon commented Jun 16, 2020

Even with a should('contain', 'text'), it doesn't throw, so it must have the correct element selected, but continues to click the wrong one. What's worse is that it alternates; the first run through, it works as expected while the second has this issue. The results continue to alernately repeat through the third, fourth, etc runs.

Per comments in #6165, I can confirm that .click({ force: false}) makes it work.

Turns out that I just had to wait(2000) (until #1296) after clicking for an asynchronous module to load, which was causing some weird rendering issues.

@jennifer-shehane
Copy link
Member

This issue still exists in Cypress 4.10.0.

@jennifer-shehane jennifer-shehane changed the title v3.5.0 cy.click() doesnt seem to select the right element cy.click() doesn’t select element in custom dropdown component Jul 9, 2020
@sainthkh
Copy link
Contributor

sainthkh commented Aug 3, 2020

I confirmed that the behavior @vramana said is true. 'mousemove' event does move autocomplete window to the left.

This behavior didn't happen before 3.5.0 because mousemove event wasn't supported. (It's added with #3030.)

When you comment out the line below:

events.push({ type: 'mousemove', ...mousemove() })

The test works correctly.

And the 'mousemove' event is sent at:

const preventedDefault = !el.dispatchEvent(evt)


This 'mousemove' event changes the style of popper. It removes the transform:

Before mousemove:

Screenshot from 2020-08-03 11-28-48

After mousemove:

Screenshot from 2020-08-03 11-30-00

And these values are computed by computeStyle at:

https://github.com/popperjs/popper-core/blob/0a2329323252fd287f263c28951883b35095082a/packages/popper/src/modifiers/computeStyle.js#L88

@sainthkh
Copy link
Contributor

sainthkh commented Aug 5, 2020

I found the cause. It's because of the click event simulation.

In native settings, the code flow after clicking menu is like this:

destroy
Popper constructor
update() with isDestroyed false
pointerdown event
mousedown event
update() with isDestroyed false
pointerup event
mouseup event
click event
destroy
update() with isDestroyed true => update is ignored

In Cypress settings, the code flow is like this:

destroy
Popper constructor
pointerdown event
mousedown event
pointerup event
mouseup event
click event
destroy
update() with isDestroyed true => update is ignored

As you can see, update() is not called. That's why the element is not relocated below the text field.

Although we know what the problem is, the solution is a bit hard. We need to give time for browsers to execute event handlers after an event is fired. To do so, we might need to restructure actionability.

Maybe, native event(#311) can be the solution.

@binary-koan
Copy link

In case this helps anyone else, my workaround for Material UI Autocomplete is to use keyboard controls to select the item. For example, to select the first item:

cy.get('.my-material-autocomplete input').type('{downarrow}{enter}')

@ashetty-womply
Copy link

ashetty-womply commented Nov 27, 2020

@binary-koan 's solution worked for me.
I have an autocomplete field for state. Using {enter} worked.

cy.get("#state").clear().type('New {downarrow}{downarrow}{enter}');

@wanderleydrumond
Copy link

wanderleydrumond commented Aug 11, 2021

I also have the same issue with version 8.2.0.
I also tried cy.select() unsuccessfully.

@GarrisonD
Copy link

Also for Cypress 10.3.1

@GarrisonD
Copy link

Passing force: true to .click() solves the issue.

According to the docs the force option controls waiting for actionability.
Why doesn't Cypress throw an error about an un-actionable element then?

@roger-ngx
Copy link

Passing force: true to .click() solves the issue.

According to the docs the force option controls waiting for actionability. Why doesn't Cypress throw an error about an un-actionable element then?

this works with my popper

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/driver This is due to an issue in the packages/driver directory stage: ready for work The issue is reproducible and in scope stale no activity on this issue for a long period topic: cy.click 🖱 topic: native events type: regression A bug that didn't appear until a specific Cy version release v3.5.0 🐛 Issue present since 3.5.0
Projects
None yet
Development

No branches or pull requests