cypress-image-snapshot icon indicating copy to clipboard operation
cypress-image-snapshot copied to clipboard

Test failing because of images sizes are not same

Open Anuradha4dm opened this issue 3 years ago • 5 comments

when the test is running in different monitors , passing only the monitor that base image is taken. I have taken the initial image (base image) in a large screen and when i try to run the test in smaller screen then the error pop up

this is the configuration

addMatchImageSnapshotCommand({ failureThreshold: 0.01, //threshold for entire image failureThresholdType: 'percent', //percent of image or number of pixels customDiffConfig: { threshold: 0.1 }, //threshold for each pixel capture: 'viewport', //capture viewport in screenshot allowSizeMismatch:true });

this is the error message error

Anuradha4dm avatar Aug 11 '21 12:08 Anuradha4dm

even with viewport this issue exists, I believe the issue is already raised

Vishwaas avatar Aug 20 '21 13:08 Vishwaas

There is no solution for this. You have to use the same docker container everytime to get the same size images.

hassanzohaib avatar Sep 10 '21 11:09 hassanzohaib

wouldnt that make testing extremely difficult

Vishwaas avatar Sep 14 '21 02:09 Vishwaas

Free screenshot comparison cannot be easy :) Here, Gleb was explaining the things related to the question.

leonid-sviderskii-mtl avatar Sep 20 '21 22:09 leonid-sviderskii-mtl

I managed to get cypress to work on macOS where it produces the same screenshots in the runner and e2e-headless.

I haven't tested in CI yet.

When you run cypress for e2e be sure to use the browser chrome flag in a before browser launch event.

./node_modules/.bin/cypress run --browser chrome

and then add these chrome flags to plugins/index.js

 on("before:browser:launch", (browser, launchOptions) => {
      console.log("launching browser %s is headless? %s",
        browser.name,
        browser.isHeadless
      );

    if (browser.name !== "chrome") throw new Error("Must use Chrome");

    launchOptions.args.push("--force-device-scale-factor=1");
    launchOptions.args.push("--disable-gpu");
    launchOptions.args.push("--force-color-profile=srgb");

    // IMPORTANT: return the updated browser launch options
    return launchOptions;
  });

sirganya avatar Jan 07 '22 17:01 sirganya