#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Playwright Interview Q&A · #34

Can Playwright capture videos during test execution?

By Uncodemy Editorial Team · Updated 16 Nov 2026

Yes. Playwright can record a video of every page a test opens, as a .webm file. In Playwright Test you switch it on with one config option; when you use the library directly, you ask for it when creating a browser context. Recording works in Chromium, Firefox and WebKit, and it works in headless mode, which is the usual case on CI.

Turning it on in Playwright Test

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

export default defineConfig({
  retries: process.env.CI ? 2 : 0,
  use: {
    video: 'retain-on-failure',
  },
});

The value decides which runs keep their video:

ModeKeeps a video for
'off'Nothing (the default)
'on'Every test
'retain-on-failure'Failed tests only; passing tests' videos are deleted
'on-first-retry'The first retry of a failed test
'on-all-retries'Every retry
'retain-on-first-failure'The first failed run only

retain-on-failure is a good default for CI: you get evidence for failures without filling the disk with videos of passing tests. Recent versions list a few more combinations; check the video option in the docs for your version.

Smaller files: set the size

// in a spec file, or under use: in the config
test.use({
  video: { mode: 'on', size: { width: 640, height: 360 } },
});

By default the video is scaled to fit within 800 × 800 pixels. A smaller size keeps artefacts light when you upload them from CI.

Where the files go

Each test gets a folder under test-results/, named after the file, test and project, and the video is saved there as video.webm. In a test run with video: 'on', the folder for a test named "vid" in video.spec.ts was test-results/video-vid-chromium/. The HTML report (npx playwright show-report) embeds the video next to the error, so most people never open the folder.

Recording without the test runner

// record.mjs  (ES module, so top-level await works)
import { chromium } from 'playwright';

const browser = await chromium.launch();
const context = await browser.newContext({
  recordVideo: { dir: 'videos/', size: { width: 640, height: 360 } },
});
const page = await context.newPage();
await page.goto('https://example.com');

const video = page.video();
await context.close();                    // the file is finished only now
console.log(await video?.path());         // videos/page@<id>.webm
await video?.saveAs('videos/home.webm');  // copy with a readable name
await browser.close();

Gotchas

Related: screenshots in Playwright, recording tests with codegen (a different kind of "recording") and browser isolation.

Want to master Playwright hands-on?

Join Uncodemy's Playwright Automation Testing Course in Noida — Dedicated Placement Support.

Explore the Course →