Quick Start¶
This guide walks you through capturing a trace and exploring the viewer.
Capture a trace¶
From the root of your Behave project (the directory containing features/):
behave-trace will:
- Register the
TraceFormatteras a Behave formatter (via entry point). - Collect execution events: features, scenarios, steps, statuses, durations.
- Capture attachments (screenshots, DOM, logs) from your
environment.py. - Serialize the trace to
trace.jsonwhen the test run completes.
What you'll see¶
USING RUNNER: behave.runner:Runner
Trace written to: trace.json
View with: behave-trace show trace.json
1 feature passed, 0 failed, 0 skipped
4 scenarios passed, 0 failed, 0 skipped
20 steps passed, 0 failed, 0 skipped
Took 0min 0.011s
Visualize the trace¶
The viewer opens in your browser at http://127.0.0.1:<port> with:
- Timeline — colored segments per step (green = passed, red = failed).
- Filmstrip — screenshots captured during execution.
- Detail tabs — Steps, Screenshots, Snapshot (DOM), Console (logs), Error.
- DOM snapshot diff — switch between before/after, split, and diff views with added/removed elements highlighted.
- Feature tree — collapse/expand all or sort scenarios by name, duration, or status.
- Breadcrumb — "Feature > Scenario" path above the step list; click the feature to locate it in the sidebar.
- Live progress — updates stream in real time while running Behave from the viewer.
- Stats — feature/scenario/step counts, pass/fail breakdown.
One-step alternative: behave-trace run¶
You can also capture and visualize in a single step:
This runs Behave with the trace formatter, then opens the viewer automatically.
Add --watch to re-run on file changes.
Capture attachments¶
Add to your features/environment.py:
from behave_trace import attach_screenshot, attach_dom, log
def after_step(context, step):
if step.status == "failed":
attach_screenshot(context, context.driver, name="failure.png")
attach_dom(context, context.driver, name="dom.html")
log(context, f"URL at failure: {context.driver.current_url}")
See Attachments for the full API.
Example project¶
The repository includes a working example at examples/calculator/:
The example demonstrates screenshots, DOM snapshots, logs, and a failing scenario (division by zero).
Next steps¶
- CLI — every command, flag, and option.
- Attachments — screenshots, DOM snapshots, and logs.
- Python API — use behave-trace as a library.
- Architecture — internal design and data flow.
- Contributing — how to contribute.