.should('not.be.visible') fails when elem out of viewport
See original GitHub issueCurrent behavior:
cy.get().should('not.be.visible')
fails even when DOM element is not in viewport.
It seems I’m not the only one reporting this behavior.
Desired behavior:
Acc to doc, only actionable commands should autoscroll DOM to viewport.
How to reproduce:
// ensure small viewport
cy.viewport( 999, 200 );
// ensure scrollbar is disabled, for good measure (though it doesn't seem Cypress cares)
cy.window().then( window => {
window.$("body").css("overflow-y", "hidden");
});
// manually test for whether elem is out of viewport -- PASSES
cy.get(".elem").first().then( $el => {
const bottom = Cypress.$( cy.state("window") ).height();
const rect = $el[0].getBoundingClientRect();
expect( rect.top ).to.be.greaterThan( bottom );
expect( rect.bottom ).to.be.greaterThan( bottom );
expect( rect.top ).to.be.greaterThan( bottom );
expect( rect.bottom ).to.be.greaterThan( bottom );
});
// FAILS
cy.get(".elem").first().should("not.be.visible");
- Operating System: win7x64
- Cypress Version: 1.0.3
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (6 by maintainers)
Top Results From Across the Web
Elements Visible In The Current Viewport - Gleb Bahmutov
If the top of the element is larger than the viewport height, then the element is still below the current viewport. Similarly, we...
Read more >Is an element that's outside the viewport considered visible?
Even if it's not in the viewport - and you'd need to scroll to make it appear on screen - it is still...
Read more >Check Visible Elements In The Current Viewport - YouTube
This video shows how to wait for the loading elements in the current viewport to go away. We will use the current window...
Read more >Check If an Element is Visible in the Viewport in JavaScript
If the element is in the viewport, the function returns true . Otherwise, it returns false . Checking if an element is visible...
Read more >content-visibility | CSS-Tricks
The content-visibility property in CSS indicates to the browser whether or not an element's contents should be rendered at initial load time ...
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 Free
Top 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
For readers in the future, you can add custom commands in
cypress/support/commands.js
like so:and then in your tests use it like so:
Inspired by @Whassup, I rewrote the command as an assertion. Simply paste the following into a
cypress/support/assertions.js
file and doimport './assertions';
in yourcupress/support/index.js
file.Usage: