Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take screenshot on failure

Is there an easy way to tell Playwright (JS) to take screenshots on test failure?

like image 928
David Pongo Avatar asked Nov 01 '25 19:11

David Pongo


1 Answers

I'm quoting Playwright Docs about screenshots

// playwright.config.js file
import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    screenshot: 'only-on-failure',
  },
});

Screenshot setting modes are "off"|"on"|"only-on-failure" in your case only-on-failure is what you're looking for.

v1.49 Update

As @sahmeepee mentioned in his comment, since v1.49 there is a new option on-first-failure that captures screenshot after each test's first failure only - relevant when setting up the retry mechanism.

export default defineConfig({
  use: {
    screenshot: 'on-first-failure',
  },
});
like image 144
I.sh. Avatar answered Nov 04 '25 08:11

I.sh.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!