Closed Kamilius closed 4 years ago
I am experiencing this same issue using Cypress 3.7.0 and cypress-plugin-snapshots 1.2.9
This is more a Cypress bug. Not sure if I can fix this.
I'm pretty sure it's not an issue of this plugin, but if anyone still has this problem, here's how I managed to solve it based on what I found at https://github.com/cypress-io/cypress/issues/2102 , which is basically giving custom window size arguments to the browser upon launch:
// cypress/plugins/index.js
const { initPlugin } = require('cypress-plugin-snapshots/plugin');
module.exports = (on, config) => {
initPlugin(on, config);
on('before:browser:launch', (browser = {}, args) => {
if (browser.name === 'electron') {
args.width = 1920;
args.height = 1080;
return args;
}
if (browser.name === 'chrome') {
args.push('--window-size=1920,1080');
return args
}
});
return config;
};
In my case I set it to 1920x1080, but it was necessary to put the event handler after initPlugin(on, config);
. If I put the handler before that line, the custom arguments would not be pushed.
It's an issue with Cypress. Check here
Describe the bug I was developing a snapshots for all of my active pages (for visual regression testing automation) using UI
$ cypress open
and viewport set to1440x900
withcy.viewport('macbook-15');
on a global level.When tried to run everything headless using
cypress run
, started getting errors everywhere. Diff shown me, thatactual
image snapshot differs fromexpected
via viewport size. After checking actual resolution of generated images, got following results:expected
image size was as configured -1440px x 900px
actual
image size was1280 × 720
Tried already defining a viewport width/height explicitly inside
cypress.json
or even passing as CLI parameters. None of them helped.To Reproduce Steps to reproduce the behavior:
beforeEach()
block inside existing test which usescy.document().toMatchImageSnapshot();
cy.viewport(1440, 900);
inside of thisbeforeEach()
blockcypress open
(UI version of Cypress)1440x900px
Electron
withcypress run
diff
andactual
actual
image dimensions and you'll see that it's1280 × 720
for some reason, ignoring viewport configuration.Same steps above can be repeated, while moving
beforeEach() { cy.viewport(1440, 900); }
into globalcommands.js
, or even specifying them insidecypress.json
or passing asCLI
parameters intocypress run
.Expected behavior Images taken both during
cypress open
orcypress run
are respecting custom viewport configuration. In short there should be no difference in dimensions between images taken undercypress open
andcypress run
.Screenshots
![Campaign Insight Paused tab Placeholder #0](https://user-images.githubusercontent.com/3115794/67843052-efe8dd00-fb03-11e9-8a52-94e965a79928.png)
Desktop (please complete the following information):