TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
Playwright / Chapter 49 of 60~18 min • Beginner
Chapter 49Playwright

Screenshots and videos

Screenshots capture visual state and help investigate failures. page.screenshot can save an image of a page or locator.screenshot can capture an element. Video is configurable per test context. Artifacts can include sensitive screen data.

How it works

Step-by-step walkthrough

  1. Create a page
  2. Capture a screenshot
  3. Enable failure artifacts in config

Example

TypeScript
import { test, expect } from '@playwright/test';

test('chapter 49 practice', async ({ page }) => {
  await page.setContent('<h1>Screenshot demo</h1>');
  await page.screenshot({ path: 'demo.png', fullPage: true });
  // Config use options: screenshot: 'only-on-failure', video: 'retain-on-failure'
});
Expected result: demo.png is written in the working directory
💡 Point to remember
Avoid exposing credentials or personal data in screenshots and videos.

✎ Your practice task

Capture only the heading with page.getByRole('heading').screenshot({ path: 'heading.png' }).

Knowledge check

Which method captures a page image?

🌐 Continue learning