Trace viewer and step-by-step debugger for Behave BDD.
Project description
behave-trace
Trace viewer and step-by-step debugger for Behave BDD.
Captures execution data (steps, statuses, durations, screenshots, DOM snapshots, logs) and visualizes them in a Playwright-inspired web viewer with timeline, filmstrip, and per-step detail tabs.
Quickstart
# 1. Install
pip install behave-trace
# 2. Register the formatter — add to behave.ini in your project root:
# [behave.formatters]
# behave-trace = behave_trace.formatter:TraceFormatter
# 3. Capture — run Behave with the formatter
behave --format behave-trace -o trace.json
# 4. Visualize — open the viewer
behave-trace show trace.json
The viewer opens in your browser at http://127.0.0.1:<port> with a dark-themed
SPA showing features, scenarios, steps, screenshots, and errors.
How it works
┌──────────┐ ┌──────────────┐ ┌───────────┐ ┌──────────────┐
│ Behave │────▶│ Formatter │────▶│ Serializer │────▶│ trace.json │
│ runner │ │ (collector) │ │ (JSON) │ │ │
└──────────┘ └──────────────┘ └───────────┘ └──────┬───────┘
│
┌────────────────────────────────────────┘
▼
┌──────────────┐ ┌──────────────────┐
│ behave-trace │────▶│ Browser SPA │
│ show │ │ (Alpine.js) │
│ (HTTP server)│ │ Dark theme │
└──────────────┘ └──────────────────┘
Two-phase model (like Playwright Trace Viewer):
-
Capture — The
TraceFormatterhooks into Behave's formatter API and collects execution events into aTracedata model. Attachments (screenshots, DOM, logs) are captured viaattach_screenshot(),attach_dom(), andlog()helpers inenvironment.py. -
Visualize —
behave-trace showloads the trace JSON, starts a local HTTP server (stdlib only, no dependencies), and opens the viewer SPA in a browser.
Capturing attachments
Add to your environment.py:
from behave_trace import attach_screenshot, attach_dom, attach_text, attach_network, log
def after_step(context, step):
# Log the current URL after every step
log(context, f"URL: {context.driver.current_url}")
if step.status == "failed":
attach_screenshot(context, context.driver, name="failure.png")
attach_dom(context, context.driver, name="dom.html")
log(context, f"Step failed: {step.name}", level="error")
The viewer will show screenshots in the filmstrip and detail tabs, with before/after DOM snapshot toggling. See the attachments guide for the full API.
CLI
# Show trace in browser
behave-trace show trace.json
# Show on specific port, don't open browser
behave-trace show trace.json --port 8080 --no-browser
# Run behave with the trace formatter, then open the viewer
behave-trace run features/
# Run with tags and watch mode
behave-trace run features/ --tags @smoke --watch
# Run from the UI (no initial trace required)
# The viewer opens even if behave fails. A "Run all" button lets you
# execute tests from scratch; selected scenarios can also be re-run.
behave-trace run --no-browser
# Version
behave-trace --version
Run from the UI
behave-trace run starts the viewer even if the initial Behave run fails or no
features have been executed yet. The viewer then shows a "Run all" button in
the header (and in the empty state) that triggers a fresh Behave execution
(POST /api/run).
While tests are running the viewer receives real-time status updates via Server-Sent Events (SSE), and the trace is reloaded automatically when the run finishes. You can also select one or more scenarios and re-run only those with "Run selected".
When watch mode is active, the viewer header shows an "Auto-run" toggle.
Enable it to re-execute Behave automatically whenever the watched *.feature or
*.py files change (debounced 500ms). Disable it to keep the viewer running and
reload the trace manually.
Development
# Install in editable mode with dev dependencies
pip install -e ".[dev]"
# Or use the Makefile shortcut
make dev
# Lint
ruff check .
ruff format --check .
# Type check
mypy --strict behave_trace
# Run tests
pytest tests/ -v
# E2E tests (meta: Behave testing Behave)
behave tests/e2e/
# Build
python -m build
Requirements
- Python 3.11+ (tested on 3.11, 3.12, 3.13)
behave >= 1.2.6(installed automatically)- No other runtime dependencies (viewer uses only Python stdlib)
Project structure
behave_trace/
__init__.py # Public API, formatter registration
__main__.py # python -m behave_trace entry point
formatter.py # Behave formatter (TraceFormatter)
collector.py # Event collector → Trace model
models.py # Dataclasses: Trace, Feature, Scenario, Step, etc.
serializer.py # JSON load/save
attach.py # Attachment helpers (screenshot, DOM, text, network, log)
runner.py # Behave runner (subprocess wrapper)
watcher.py # File watcher for --watch mode
utils.py # Utilities (format_duration, safe_str)
cli/
app.py # argparse CLI with `show` and `run` subcommands
viewer/
server.py # stdlib HTTP server (ThreadingHTTPServer)
browser.py # Browser opener (Chrome app mode)
assets/
index.html # SPA shell (Alpine.js from CDN)
css/viewer.css # Dark theme styles
js/viewer.js # Alpine.js component logic
Documentation
Full documentation is available at mathiaspaulenko.github.io/behave-trace.
Contributing
Contributions are welcome! See CONTRIBUTING.md for setup, commands, and the release process.
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file behave_trace-1.2.1.tar.gz.
File metadata
- Download URL: behave_trace-1.2.1.tar.gz
- Upload date:
- Size: 97.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
408f597b9f924c70b6e89e0410dd18207f502cd96afceed14ce364a835c4d467
|
|
| MD5 |
7a9a8e9cb7017558eeae1b7c8c50b06b
|
|
| BLAKE2b-256 |
837a422035a15ccfd2db0ad80f4e33572338b0266c0e70b729d1e939accf69b9
|
Provenance
The following attestation bundles were made for behave_trace-1.2.1.tar.gz:
Publisher:
release.yml on MathiasPaulenko/behave-trace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
behave_trace-1.2.1.tar.gz -
Subject digest:
408f597b9f924c70b6e89e0410dd18207f502cd96afceed14ce364a835c4d467 - Sigstore transparency entry: 2339942343
- Sigstore integration time:
-
Permalink:
MathiasPaulenko/behave-trace@179291159101d63c33c0a8f1fbcb878a91d889d9 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/MathiasPaulenko
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@179291159101d63c33c0a8f1fbcb878a91d889d9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file behave_trace-1.2.1-py3-none-any.whl.
File metadata
- Download URL: behave_trace-1.2.1-py3-none-any.whl
- Upload date:
- Size: 54.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7344cd585172d3525b053c6d213ed57b6ed026e92df1308cc3dec8a6cb25dfe
|
|
| MD5 |
b19cb63a0a893d2006fb2988cb8c1d85
|
|
| BLAKE2b-256 |
5cda77f62c83fd9ab2a1d05170a3ef1f0227a0277e7c23bbabd25eaa02da7263
|
Provenance
The following attestation bundles were made for behave_trace-1.2.1-py3-none-any.whl:
Publisher:
release.yml on MathiasPaulenko/behave-trace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
behave_trace-1.2.1-py3-none-any.whl -
Subject digest:
b7344cd585172d3525b053c6d213ed57b6ed026e92df1308cc3dec8a6cb25dfe - Sigstore transparency entry: 2339942370
- Sigstore integration time:
-
Permalink:
MathiasPaulenko/behave-trace@179291159101d63c33c0a8f1fbcb878a91d889d9 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/MathiasPaulenko
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@179291159101d63c33c0a8f1fbcb878a91d889d9 -
Trigger Event:
push
-
Statement type: