Playwright + JS · Lesson 31 of 35
Module 31: Screenshots, Videos & Trace Viewer
Try it yourself
Implement formatTraceFilename:
traces/${testName.toLowerCase()}-attempt-${attempt}.zip.The editor has a worked example. Read it, tweak it, then press Mark as complete.
playwright.config.jsexport default {
use: {
trace: "retain-on-failure",
screenshot: "only-on-failure",
video: "retain-on-failure",
},
};View trace in browser:
npx playwright show-trace test-results/trace.zipPlaywright's Trace Viewer is widely regarded as one of the best debugging tools in the industry. It records a full timeline of DOM snapshots, network calls, console logs, and video so you can step through failed tests with ease. In this lesson, we will configure screenshots, videos, and trace capture for seamless failure investigation. Let's inspect our traces!
Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Capturing video and DOM traces for 1000 passing tests takes substantial CPU and disk space. 'retain-on-failure' keeps builds fast while capturing artifacts when failures occur.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.