Playwright Config Screenshot

Profile picture for user arilio666

In our take screenshot in the playwright article, we discussed how we could capture screenshots of the current view, full page, and screenshots of a particular section or element. In this article, let's discuss how to control screenshot capturing automatically using the configuration option screenshot.

Table of Contents

  1. Capture a screenshot after each test
  2. Do not capture screenshots
  3. Screenshot on failure
  4. Video Tutorial

Capture a screenshot after each test

To capture a screenshot after each test, set the screenshot option value to on in the playwright configuration file.

const config = {
  use: {
      screenshot: 'on',

Screenshots will be attached to the HTML report, and Screenshots will appear in the test output directory, typically test-results. You can also view it from the playwright-report/data folder.

Do not capture screenshot

By default, screenshots are off. You can also set the screenshot option to off in the configuration file if you do not want to capture screenshots.

screenshot: 'off'

Screenshot on failure

In case you want to avoid capturing a screenshot after each test and want to take a screenshot only when a test fails. You can set the screenshot option value to only-on-failure.

screenshot: 'only-on-failure'

Video Tutorial: Playwright Config Screenshot