Skip to main content
The Video class enables recording videos of browser sessions during test execution. Videos are useful for debugging test failures and understanding user interactions.

Overview

Access video through the page object:

Methods

start

Starts video recording.
{ width: number, height: number }
Video frame size. If not specified, uses the viewport size.
Returns: Promise<void>

stop

Stops video recording and optionally saves it to a file.
string
Path to save the video file. If not specified, the video is saved to the test output directory.
Returns: Promise<void>

path

Returns the path to the video file.
Returns: Promise<string> Note: This method throws an error when connecting remotely. Use saveAs() to save a local copy instead.

saveAs

Saves the video to the specified path.
string
required
Path where the video should be saved.
Returns: Promise<void>

delete

Deletes the video file.
Returns: Promise<void>

Examples

Recording a video

Custom video size

Saving video to custom location

Conditional video recording

Remote connection video

Video with manual start/stop

Configuration

Configure video recording in playwright.config.ts:
Options:
  • 'on': Record video for each test
  • 'off': Do not record video
  • 'retain-on-failure': Record video for each test, but remove it if test passes
  • 'on-first-retry': Record video only when retrying a test for the first time

Per-project configuration

Video Format

Playwright records videos in WebM format with VP9 codec. Videos include:
  • Browser viewport rendering
  • Mouse movements and clicks
  • Keyboard input
  • Page navigations
  • Console messages (in separate trace files)

Storage Considerations

Video files can be large. Best practices:
  • Use 'retain-on-failure' or 'on-first-retry' modes
  • Delete videos in CI/CD after test completion
  • Use lower resolution for faster recording: { width: 800, height: 600 }
  • Consider using traces instead of videos for detailed debugging