Playwright Automatic Screenshots

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'
Thu, 12/22/2022 - 10:08
Ashwin possesses over five years of experience in the Quality Assurance industry and is currently serving as a Technical Lead at iVagus. His expertise encompasses a broad range of technologies, including Cypress, Rest Assured, Selenium, Cucumber, JavaScript and TypeScript.

Video Tutorial: Playwright Automatic Screenshots