jaredpalmer / cypress-image-snapshot

Catch visual regressions in Cypress
MIT License
887 stars 160 forks source link

Test failing because of images sizes are not same #219

Open Anuradha4dm opened 3 years ago

Anuradha4dm commented 3 years ago

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
Vishwaas commented 3 years ago

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

hassanzohaib commented 2 years ago

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

Vishwaas commented 2 years ago

wouldnt that make testing extremely difficult

leonid-sviderskii-mtl commented 2 years ago

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

sirganya commented 2 years ago

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;
  });