Playwright + Python · Lesson 32 of 37

0/37 done

Module 32: Screenshots, Video & Trace

32. Deep Failure Analysis with Playwright Trace Viewer

16 minlesson

Your task

Implement start_tracing_session(context):

  1. context.tracing.start(screenshots=True, snapshots=True)

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

Configuring Tracing in Python

python
# Start tracing before actions:
context.tracing.start(screenshots=True, snapshots=True, sources=True)

# Run test actions...

# Stop and save trace archive:
context.tracing.stop(path="traces/failure_trace.zip")

# View trace with CLI:
# playwright show-trace traces/failure_trace.zip

Key Takeaways & Walkthrough Summary

When tests fail on remote CI runners, Playwright's Trace Viewer provides an interactive time-travel debugging experience. In this lesson, you will master configuring traces, screencasts, and viewing failure traces. Let's master the Trace Viewer!

Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

How do I automatically record traces only on failure with pytest?

Run pytest with 'pytest --tracing=retain-on-failure' to automatically save traces only when tests fail.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip