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

how to deal with sticky CSS? #57

Closed
Pomax opened this issue Nov 29, 2021 · 6 comments
Closed

how to deal with sticky CSS? #57

Pomax opened this issue Nov 29, 2021 · 6 comments

Comments

@Pomax
Copy link

Pomax commented Nov 29, 2021

It looks like screenshots are based on "scrolling the page", which doesn't work for pages with sticky and fixed CSS positioning, leading to hilariously wrong screenshots like this one:

image

Is there any way to tell the screenshooter to not scroll, but use the browser's built in "take a full page screenshot" function?

@narinluangrath
Copy link
Contributor

You might find this useful. https://docs.cypress.io/api/commands/screenshot#Full-page-captures-and-fixed-sticky-elements
An alternative I've found is to make the viewport height huge (like 5000px).

@PippoRaimondi
Copy link
Collaborator

This should work:

cy.get('.sticky-header').invoke('css', 'position', 'absolute').compareSnapshot('yourVisualRegressionTestName')

otherwise a big resolution so it fits the entire page should do.

@Pomax
Copy link
Author

Pomax commented Dec 1, 2021

Having to manually alter the page in order to get a screenshot of what the page is supposed to look like kind of defeats the purpose =)

Chrome and FF both have "take a full page screenshot" functionality built in, is there a way to tap into that instead? e.g. in Chrome it's under dev tools -> [⋮] menu -> "run command" and then type screenshot; in FF there's a "take screenshot" icon on the main UI button bar that lets you pick "full page", both of which I would assume are actions that can be triggered by Cypress? (or... I hope? It would be weird if they didn't tap into those functions)

@Pomax
Copy link
Author

Pomax commented Dec 1, 2021

Ah, according to https://docs.cypress.io/api/cypress-api/screenshot-api#Arguments this is just a standard option.

@Pomax
Copy link
Author

Pomax commented Dec 1, 2021

hm, nope - after testing, that's still a very weird "scroll and tesselate", so I guess that won't get us actual real screenshots still =(

@PippoRaimondi
Copy link
Collaborator

this seems to be a none issue now, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants