Playwright + Java · Lesson 33 of 38
Module 33: Screenshots, Video & Trace
Your task
Implement startTracingHelper:
Write it in the editor, then press Check answer (Ctrl + Enter).
import java.nio.file.Paths;
// Start tracing before test runs:
context.tracing().start(new Tracing.StartOptions()
.setScreenshots(true)
.setSnapshots(true)
.setSources(true));
// Execute tests...
// Stop and save trace archive on failure:
context.tracing().stop(new Tracing.StopOptions()
.setPath(Paths.get("traces/failed-test-trace.zip")));
// View trace with CLI:
// mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="show-trace traces/failed-test-trace.zip"When an automated test fails on CI, a simple stack trace is never enough. Playwright's Trace Viewer records screencasts, DOM snapshots, network request waterfalls, and action timelines. In this lesson, you will master configuring and analyzing traces. Let's investigate failures!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Tracing has minimal overhead (~3-5%). You can configure it to retain traces only on failure to keep disk usage low.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___