cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.77k stars 3.17k forks source link

Component testing - browser window dimension will impact screenshot viewport dimension #23301

Open gsouf opened 2 years ago

gsouf commented 2 years ago

Current behavior

When taking a screenshot the dimension of the viewport of the screenshot will be impacted by the size of the browser window.

That will have effects when component dimensions are relative ie %, vh, vw.

Desired behavior

Screenshots made in components testing to be only dependent on the configured viewport dimension and not to be impacted by the browser window dimensions.

Test code to reproduce

Clone the repo https://gitlab.com/souf/react-webpack-playground/-/tree/cypress-screen-dimensions using branch cypress-screen-dimensions.

run yarn install and yarn cypress:open.

Open the component testing for the component "App" and make sure you windows is wide enough to not scale down the viewport as per the indicator in the top right hand corner: image

Tests are working

Now size down the browser's window to have the viewport scaled down:

image

Tests are failing as per the following screenshot diff (left is expect / right is actual):

image

see screenshot in cypress/snapshots/__diff_output__

Cypress Version

10.4.0

Node version

16.x

Operating System

linux

Debug Logs

nc

Other

I suspect this could somehow share some with #23300 due to the way screenshots are processed

JasonFairchild commented 2 years ago

I think I'm getting this as well. I can't tell anything from the app viewport with it at just 10%. Affects videos too of course. I think it might be interfering with our VRT as well. CurrencyInput component -- default derived format and most input props (failed)

JasonFairchild commented 1 year ago

So I happened across a type of workaround for this, in case anyone is interested. This cypress doc talks about using browser launch options to force screen size/pixel ratio. I had to remove the "browser.isHeadless" from the conditional to have VRT snapshots match between headless and headed browser runs though. After doing that, my videos and screenshots are able to be made out visibly (not 10% of viewport) like this.

image
eduardlind commented 1 year ago

Are there any plans to work on it? As far as I see now, there is no ability to make a screenshot of page or element. Also it affects heavily visual testing(it breaks is totally). I tried solution from @JasonFairchild but it didn't work(electron).