Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cypress custom command to check if an element is in the viewport
Cypress.Commands.add('shouldBeInViewport', { prevSubject: true }, subject => {
cy.document().then(doc => {
let clientHeight = doc.documentElement.clientHeight
let viewportTop = doc.documentElement.scrollTop
let viewportBottom = viewportTop + clientHeight
let subjectTop = subject[0].offsetTop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment