Assertion should('not.be.visible') doesn't work as expected
See original GitHub issueCurrent behavior
Assertion cy.get('[data-cy=an_invisible_button').should('not.be.visible');
fails with Timed out retrying: Expected to find element: [data-cy=an_invisible_button], but never found it.
Desired behavior
The assertion should be pass, because the invisible button is really not visible.
Test code to reproduce
cy.get(‘[data-cy=an_invisible_button’).should(‘not.be.visible’);
Versions
Bug was visible in Cypress version 6.0.0 Last known working Cypress Verion: 5.1.0 (Only tested because I updated to 6.0.0 from that version)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Cypress should not.exist or not.be.visible - Stack Overflow
Hey, the custom command sounds like a good solution. Much easier than the Chai assertion, for sure. I do know - in this...
Read more >should | Cypress Documentation
Create an assertion. Assertions are automatically retried until they pass or time out. An alias of .and() Note: .should() assumes you are already....
Read more >Cypress Tip: Don't Overuse the Visibility Assertion - iheartjs
First, it's unnecessary because of two implicit behaviors of Cypress: actionability assertions and command retry-ability. Cypress will not ...
Read more >Verifying that Element Should not Exist in Cypress - Webtips
Want to verify that an element should not exist in Cypress? You need to chain the should assertion off from cy.get command:.
Read more >Assertions | Cypress examples (v9.5.0) - Gleb Bahmutov
The callback will be retried, but the assertions will not be shown as nicely in ... Load. The command below fails because the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Both assertions still exist in Cypress’s current version. You need to be specific about what you are asserting about an element.
.should('not.be.visible')
for elements that exist in the DOM but would not be visible to a fully sighted person..should('not.exist')
for elements that do not exist in the DOM, regardless of their visibility.Yes, this is expected behavior as of 6.0. Please see our Migration Guide for a detailed explanation. https://on.cypress.io/migration-guide
You’ll want to change your assert to .should(‘not.exist’) if you want to ensure it’s not in the DOM.
We understand this may be cumbersome to change but we think it’s better than having tests potentially falsely pass. We found a misspelled selector query in our own tests when updating even where it wasn’t testing what we thought.