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

fix: Chrome doesn't change resolution #399

Merged
merged 3 commits into from
Sep 14, 2023
Merged

fix: Chrome doesn't change resolution #399

merged 3 commits into from
Sep 14, 2023

Conversation

route
Copy link
Member

@route route commented Sep 13, 2023

No description provided.

@route
Copy link
Member Author

route commented Sep 13, 2023

@aaronjensen interesting but now I've got failing tests on my laptop, when this deviceScaleFactor is set to 0, though same Chrome version on github doesn't show broken tests. Same main branch was working for me for today before my experiments, but now it constantly failing for 117.

@aaronjensen
Copy link
Contributor

What are the failures? I can see if I can reproduce.

@aaronjensen
Copy link
Contributor

I see exactly one failing test, and the failure does seem related, but it may point to Chrome having changed their default scaling for headless browsers to 2x, which means that the test may be the thing that needs to be corrected. If the test produces different results on different machines, it could be that Chrome is somehow taking into account the device's scaling (I do have a high dpi monitor and my window.devicePixelRatio is 2).

  1) Ferrum::Page::Screenshot#screenshot supports screenshotting the whole of a page that goes outside the viewport
     Failure/Error: expect(ImageSize.new(f.read).size).to eq(browser.viewport_size)

       expected: [1024, 768]
            got: [2048, 1536]

       (compared using ==)
     Shared Example Group: "screenshot screen" called from ./spec/page/screenshot_spec.rb:158
     # ./spec/page/screenshot_spec.rb:16:in `block (4 levels) in <top (required)>'
     # ./spec/page/screenshot_spec.rb:15:in `open'
     # ./spec/page/screenshot_spec.rb:15:in `block (3 levels) in <top (required)>'

@aaronjensen
Copy link
Contributor

I propose that we allow deviceScaleFactor to be controlled the same way height and width is. Then the test can be set up to specify that. It should default to 0 so that it will respect the machine it is running on.

@route
Copy link
Member Author

route commented Sep 13, 2023

@aaronjensen you should remove fail-fast in .rspec file and you can see more failing tests. What OS are you on?

@aaronjensen
Copy link
Contributor

macOS Ventura

As a point of feedback, it is maximally surprising to have rspec default to fail-fast. That's an end-user choice. I would have never known until I got incredibly frustrated playing test whack-a-mole.

@aaronjensen
Copy link
Contributor

aaronjensen commented Sep 13, 2023

All of the failing tests are exactly the same. It is respecting my device scaling now. As a result all screenshots are higher resolution. That is, they are more accurate to what my device should actually produce. I'd suggest either allowing device pixel ratio to be controlled and updating those tests to control it, or updating the tests to test for a multiple of the expected size, rather than the exact size if, in fact, the CI server is passing these tests with Chrome 117

@aaronjensen
Copy link
Contributor

Alternatively, the tests can be corrected to expect pixel size when they expect pixel size, rather than the virtual device size with something like this:

def viewport_pixel_size
  evaluate <<~JS
    [window.innerWidth * window.devicePixelRatio,
     window.innerHeight * window.devicePixelRatio]
  JS
end

@aaronjensen
Copy link
Contributor

@route if you let me know what you prefer, I can work on a PR later, I think.

@route
Copy link
Member Author

route commented Sep 14, 2023

it could be that Chrome is somehow taking into account the device's scaling (I do have a high dpi monitor and my window.devicePixelRatio is 2)

I have Mac for which window.devicePixelRatio=2 and I have Linux with window.devicePixelRatio=1 on the same hiDPI monitor. So thus I guess it's OS related, and the reason why I don't see failing tests on Linux as it works for both 0 and 1 the same way (like nothing changes). But for Mac where it's set to 2 by default scaling down to 1 makes it change the scaling.

As a point of feedback, it is maximally surprising to have rspec default to fail-fast.

Yea I'll remove that, the only intention was to set it for CI to speed up build.

@route route merged commit b46d456 into main Sep 14, 2023
12 checks passed
@route route deleted the screenshot-issue branch September 14, 2023 08:00
@aaronjensen
Copy link
Contributor

The change looks good, thanks!

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

Successfully merging this pull request may close these issues.

2 participants