Playwright + JS · Lesson 31 of 35

0/35 done

Module 31: Screenshots, Videos & Trace Viewer

31. Diagnostic Artifacts & Time-Travel Trace Viewer

18 minlesson

Try it yourself

Implement formatTraceFilename:

  1. Accept testName string and attempt number.
  2. Return traces/${testName.toLowerCase()}-attempt-${attempt}.zip.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

Diagnostic Traces in playwright.config.js

javascript
export default {
  use: {
    trace: "retain-on-failure",
    screenshot: "only-on-failure",
    video: "retain-on-failure",
  },
};

View trace in browser:

bash
npx playwright show-trace test-results/trace.zip

Key Takeaways & Walkthrough Summary

Playwright'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.

Common Doubts & Lesson Q&A

Why not enable video and trace for every test run?

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.

JavaScript
Skip