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

Cypress is referencing to the wrong aliased element #17470

Closed
wlsf82 opened this issue Jul 24, 2021 · 5 comments
Closed

Cypress is referencing to the wrong aliased element #17470

wlsf82 opened this issue Jul 24, 2021 · 5 comments
Labels
stage: awaiting response Potential fix was proposed; awaiting response

Comments

@wlsf82
Copy link

wlsf82 commented Jul 24, 2021

Current behavior

I have a test that has three aliases for three different elements. They are:

cy.contains('button', 'Start')
  .as('startBtn')

cy.get('input[type="text"]')
  .as('textField')

cy.contains('button', 'Reset')
  .as('resetBtn')

As you can see, every alias refers to a different element.

The last assertion of my test is:

cy.get('@resetBtn')
  .should('not.exist')

And this exact step fails with the following error:

AssertionError: Timed out retrying after 4000ms: Expected to find element: `input[type="text"]`, but never found it.

Desired behavior

Cypress should refer to the correct element through its alias, and the tests should pass.

Test code to reproduce

Here's a draft PR that changes a sample app and updates its test, which fails with a failure that seems to be a Cypress issue: wlsf82/live-tat-code-cov#3.
And here's the failing test result from GitHub Actions https://github.com/wlsf82/live-tat-code-cov/pull/3/checks?check_run_id=3148179864.

Cypress Version

I tried on versions 8.0.0 and 7.7.0, and the issue happens on both of them.

Other

I'm using a macOS Big Sur Version 11.5

@wlsf82
Copy link
Author

wlsf82 commented Jul 24, 2021

Analyzing the failure closer, Cypress is somehow running an assertion that has already run (see screenshots.)

Screenshot 2021-07-24 at 02 29 26

Screenshot 2021-07-24 at 02 29 35

@wlsf82
Copy link
Author

wlsf82 commented Jul 24, 2021

@jennifer-shehane, would you mind looking into it, please?

@jennifer-shehane
Copy link
Member

I believe this may be a duplicate of #7413 where there's a situation where the cy.contains is not correctly viewed as a parent command.

Can you try writing cy.root().contains() to replace the cy.contains() in your case and verify whether this fixes the issue?

@jennifer-shehane jennifer-shehane added the stage: awaiting response Potential fix was proposed; awaiting response label Jul 29, 2021
@wlsf82
Copy link
Author

wlsf82 commented Jul 29, 2021

I believe this may be a duplicate of #7413 where there's a situation where the cy.contains is not correctly viewed as a parent command.

Can you try writing cy.root().contains() to replace the cy.contains() in your case and verify whether this fixes the issue?

Yup, I've used cy.root().contains('button', 'Reset') and this fixes the issue.

And it does seem to be a duplicate of the issue you mentioned. Feel free to close this one.

Thanks!

Cc @jennifer-shehane

wlsf82 added a commit to wlsf82/live-tat-code-cov that referenced this issue Jul 29, 2021
@wlsf82
Copy link
Author

wlsf82 commented Jul 29, 2021

By the way, I'll read about cy.root(). I didn't know about it. 🙇

wlsf82 added a commit to wlsf82/live-tat-code-cov that referenced this issue Jul 29, 2021
@wlsf82 wlsf82 closed this as completed Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: awaiting response Potential fix was proposed; awaiting response
Projects
None yet
Development

No branches or pull requests

2 participants