question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Device pixel ratio/density simulation

See original GitHub issue

I’m following the advice here : https://docs.cypress.io/api/commands/viewport.html#devicePixelRatio

Current behavior:

Actually we can’t simulate pixelRatio/pixelDensity with Cypress. It can be very useful for testing correct behavior around responsive images.

Desired behavior:

Have the possibility to switch the DevicePixelRatio in cypress.

Viewport dimension changes and testing the currentSrc is already very useful. Having DevicePixelRatio in cypress would enable finer tests.

Test code to reproduce

Not applicable as it’s not implemented.

It could be another option to cy.viewport()

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:38
  • Comments:6

github_iconTop GitHub Comments

4reactions
smoolincommented, Apr 21, 2022

I was able to configure device pixel ratio with these lines in my tests, YMMV:

cy.wrap(Cypress.automation('remote:debugger:protocol', {
  command: 'Emulation.setDeviceMetricsOverride',
  params: {
    // target DPR here
    deviceScaleFactor: 2,
    // width and height set to 0 remove overrides
    width: 0,
    height: 0,
    // my use case wasn't on mobile
    mobile: false,
  },
}));
3reactions
roman01lacommented, Jun 2, 2020

This could also help cypress-image-snapshot to avoid diff size of screenshots between local and CI runs https://github.com/palmerhq/cypress-image-snapshot/issues/129

Read more comments on GitHub >

github_iconTop Results From Across the Web

Device Pixel Ratio dpr - imgix Documentation
Device pixel ratio (DPR) is an easy way to convert between device-independent pixels and device pixels (also called "CSS pixels"), so that high-DPR...
Read more >
-webkit-device-pixel-ratio - CSS: Cascading Style Sheets | MDN
The -webkit-device-pixel-ratio is a non-standard Boolean CSS media feature which is an alternative to the standard resolution media feature.
Read more >
mydevice.io : web devices capabilities
name phys. width phys. height CSS width CSS height pixel ratio phys... Apple iPhone 12 Pro Max 1284 2778 428 926 3 458 Apple iPhone...
Read more >
High DPI Images for Variable Pixel Densities - WebPlatform.org
Calculating the device pixel ratio · Compare the actual distance at which the device is held to the distance for the reference pixel....
Read more >
Support different pixel densities - Android Developers
To preserve the visible size of your UI on screens with different densities, you must design your UI using density-independent pixels (dp) as ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found