Chapter 49: Screenshots and videos
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
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
- Create a page
- Capture a screenshot
- Enable failure artifacts in config
Example
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'
});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
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.