Playwright + Java · Lesson 33 of 38

0/38 done

Module 33: Screenshots, Video & Trace

33. Deep Failure Investigation with Trace Viewer & Artifacts

16 minlesson

Your task

Implement startTracingHelper:

  1. Accept BrowserContext context.
  2. Call context.tracing().start(new Tracing.StartOptions().setScreenshots(true).setSnapshots(true)).

Write it in the editor, then press Check answer (Ctrl + Enter).

Enabling Tracing in Java

java
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"

Key Takeaways & Walkthrough Summary

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.

Common Doubts & Lesson Q&A

What is the performance overhead of Tracing?

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.

Java
Skip