Search code examples
typescriptplaywright

Is there a way to disable screenshot assertions in playwright?


I am introducing screenshot testing to a project I am working on. Due to differences on screenshots generated locally (macOS) and on the CI (Linux) I decided to generate screenshots via a Github Action triggered by a comment on a PR. The issue with this approach is that running the tests locally fails due to not matching screenshots. To avoid this situation I would like to ignore calls to toHaveScreenshot to be ignored locally.

I tried to set maxDiffPixelRatio to 1 but this didn't work... Is there any other way to achieve this behavior? For instance, customizing the behavior of toHaveScreenshot? 🤔


Solution

  • To ignore screenshots locally, you could add a script to package.json, something like:

    "scripts": {
        "e2e-local": "npx playwright test --ignore-snapshots"
    }
    

    Then run that in the terminal: npm run e2e-local or just run the command directly.

    However, a problem I ran into when generating base screenshots locally causing issues on CI, was simply because my monitor was at 125% scale instead of 100%. When I changed it to 100% and regenerated the base screenshots, they worked on CI. Maybe that is worth checking out.