Back to All Questions
Question 26 of 100
Debugging
Intermediate
How to capture video in Playwright?
The Answer
Playwright can record a video of every test by enabling the `video` option in the configuration. Videos are saved per test and are invaluable for debugging failures in CI.
Deep Dive Explanation
Use `retain-on-failure` in CI to save disk space β videos are only kept when a test fails. The video file is finalized after the page/context is closed, so always close the context before reading the video path.
example.spec.ts
// In playwright.config.ts
export default defineConfig({
use: {
video: 'retain-on-failure', // Options: 'on', 'off', 'retain-on-failure', 'on-first-retry'
},
});
// Manually saving video path in a test
test('record video', async ({ page }, testInfo) => {
await page.goto('/dashboard');
// ... test steps
// Video is automatically saved after test completes
const videoPath = await page.video()?.path();
console.log('Video saved at:', videoPath);
});