Playwright/pytest test analytics reporter — navigation timeline, API call capture, network stats, failure diagnostics, and interactive HTML reports.
Project description
testrelic-playwright
A pytest + Playwright analytics reporter that generates structured JSON and HTML
reports from your Playwright test runs — capturing navigation timelines, API
call tracking, network statistics, failure diagnostics, and CI metadata. The
Python port of @testrelic/playwright-analytics.
What it does
When you run your tests with the TestRelic pytest plugin you get a JSON + HTML report that captures:
- Navigation timeline — every URL visited during each test in chronological
order, with navigation type detection (
goto, link click, back/forward, SPA route changes, hash changes). - API call tracking — HTTP method, URL, status code, request/response headers and bodies, response times, and assertions for every API call.
- Network statistics — total requests, failed requests, bytes transferred, and resource-type breakdowns (scripts, images, stylesheets, fonts, XHR).
- Test results — pass/fail/flaky status, duration, retry count, and tags.
- Failure diagnostics — error messages, source-code snippets pointing to the exact failure line, and optional stack traces.
- CI metadata — auto-detection of GitHub Actions, GitLab CI, Jenkins, and CircleCI with build id, commit sha, and branch.
- Sensitive-data redaction — AWS keys, Bearer tokens, private keys, credential URLs, and sensitive API headers / body fields.
- HTML report — self-contained interactive HTML alongside the JSON.
Quick start
1. Install
pip install pytest-playwright testrelic-playwright
playwright install
The reporter activates automatically because testrelic-playwright registers a
pytest11 entry point. No conftest.py plumbing required.
2. Write a test
Use the standard page and context fixtures from pytest-playwright. The
TestRelic plugin auto-attaches listeners and records navigation / API calls.
# tests/test_homepage.py
from playwright.sync_api import Page, expect
def test_homepage_loads(page: Page) -> None:
page.goto("https://example.com")
expect(page.locator("h1")).to_be_visible()
API tests work the same way using pytest-playwright's built-in
APIRequestContext fixture:
from playwright.sync_api import APIRequestContext
def test_fetch_posts(playwright) -> None:
request = playwright.request.new_context()
response = request.get("https://api.example.com/posts")
assert response.status == 200
3. Run
pytest
Outputs land in:
test-results/
├── analytics-timeline.json
└── analytics-timeline.html
Configuration
Reporter options can be supplied three ways (highest priority first):
- Environment variables (
TESTRELIC_API_KEY,TESTRELIC_CLOUD_ENDPOINT,TESTRELIC_UPLOAD_STRATEGY,TESTRELIC_CLOUD_TIMEOUT). pytest.ini/pyproject.tomltestrelic_optionsini block..testrelic/testrelic-config.jsonin the project root.
pytest.ini
[pytest]
testrelic_options =
outputPath=./reports/run.json
includeStackTrace=true
captureRequestBody=true
captureResponseBody=true
pyproject.toml
[tool.pytest.ini_options]
testrelic_options = [
"outputPath=./reports/run.json",
"includeStackTrace=true",
]
CLI flags
pytest --testrelic-output ./reports/custom.json
pytest --testrelic-disable # turn the reporter off for this run
pytest --testrelic-quiet # suppress banner output
Full option list
| Option | Type | Default | Description |
|---|---|---|---|
outputPath |
str | ./test-results/analytics-timeline.json |
JSON report path |
htmlReportPath |
str | derived from outputPath |
HTML report path |
includeStackTrace |
bool | false |
Include full stack traces in failures |
includeCodeSnippets |
bool | true |
Include source code around the failure line |
codeContextLines |
int | 3 |
Lines of context above / below the failure line |
includeNetworkStats |
bool | true |
Track network requests and bytes per navigation |
includeArtifacts |
bool | true |
Include screenshots and videos |
includeActionSteps |
bool | true |
Capture pytest test steps |
captureConsoleLogs |
bool | true |
Capture browser console messages |
trackApiCalls |
bool | true |
Enable / disable API call tracking |
captureRequestHeaders |
bool | true |
Capture request headers |
captureResponseHeaders |
bool | true |
Capture response headers |
captureRequestBody |
bool | true |
Capture request bodies |
captureResponseBody |
bool | true |
Capture response bodies |
redactHeaders |
list[str] | [authorization, cookie, set-cookie, x-api-key] |
Header names to redact |
redactBodyFields |
list[str] | [password, secret, token, apiKey, api_key] |
JSON body field names to scrub |
apiIncludeUrls |
list[str] | [] |
Only track API calls matching these patterns |
apiExcludeUrls |
list[str] | [] |
Exclude API calls matching these patterns |
quiet |
bool | false |
Suppress banner output |
Cloud integration
Set TESTRELIC_API_KEY and the reporter uploads the batch payload to
https://platform.testrelic.ai/api/v1/test-runs at session end.
export TESTRELIC_API_KEY=tk_live_...
export TESTRELIC_UPLOAD_STRATEGY=both # realtime | batch | both
Or use a project file:
// .testrelic/testrelic-config.json
{
"cloud": {
"apiKey": "$TESTRELIC_API_KEY",
"endpoint": "https://platform.testrelic.ai/api/v1",
"upload": "both"
},
"testrelic-repo": {
"name": "my-project"
}
}
Network failures are queued to .testrelic/queue/ and can be retried with:
testrelic-playwright drain
CLI
testrelic-playwright merge shard-1.json shard-2.json -o merged.json
testrelic-playwright serve ./test-results --port 9323
testrelic-playwright drain
testrelic-playwright version
Manual navigation hook
For navigation the auto-tracker can't see (custom routing, iframes), use
record_navigation:
from testrelic_playwright import record_navigation
def test_with_manual_nav(page, testrelic_state) -> None:
page.goto("https://example.com")
record_navigation(testrelic_state, "https://example.com/spa/profile", "spa_route")
Compatibility
- Python 3.9 – 3.12
- pytest 7.0+
- pytest-playwright 0.5+
- Playwright 1.35+
License
MIT
Project details
Release history Release notifications | RSS feed
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 testrelic_playwright-0.1.0.tar.gz.
File metadata
- Download URL: testrelic_playwright-0.1.0.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d7e4d2bd77817b591592774cd381653f54bc38b9bed195a336f6b064b02b283
|
|
| MD5 |
03ee0cb4995d42253ae28d6c6f14ee2f
|
|
| BLAKE2b-256 |
aa7e4583dfdc6f8df3984ae1f81b3b1f29cfa3c23cd612e3232ebd994a86a981
|
Provenance
The following attestation bundles were made for testrelic_playwright-0.1.0.tar.gz:
Publisher:
publish-playwright-prod.yml on testrelic-ai/testrelic-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testrelic_playwright-0.1.0.tar.gz -
Subject digest:
4d7e4d2bd77817b591592774cd381653f54bc38b9bed195a336f6b064b02b283 - Sigstore transparency entry: 1591193261
- Sigstore integration time:
-
Permalink:
testrelic-ai/testrelic-python-sdk@71360651279df85b71bb991a91d5a55f77220ef5 -
Branch / Tag:
refs/heads/prod - Owner: https://github.com/testrelic-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-playwright-prod.yml@71360651279df85b71bb991a91d5a55f77220ef5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file testrelic_playwright-0.1.0-py3-none-any.whl.
File metadata
- Download URL: testrelic_playwright-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68db901de675b0885112290b698bbd6ab45c720595093cc5e2d8fb39567641b3
|
|
| MD5 |
c4beadd3bd714954914849968fb26b91
|
|
| BLAKE2b-256 |
ec77a0e78351b5439de1b177d299462472d8f11037200bc4c52804b29190f214
|
Provenance
The following attestation bundles were made for testrelic_playwright-0.1.0-py3-none-any.whl:
Publisher:
publish-playwright-prod.yml on testrelic-ai/testrelic-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testrelic_playwright-0.1.0-py3-none-any.whl -
Subject digest:
68db901de675b0885112290b698bbd6ab45c720595093cc5e2d8fb39567641b3 - Sigstore transparency entry: 1591193273
- Sigstore integration time:
-
Permalink:
testrelic-ai/testrelic-python-sdk@71360651279df85b71bb991a91d5a55f77220ef5 -
Branch / Tag:
refs/heads/prod - Owner: https://github.com/testrelic-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-playwright-prod.yml@71360651279df85b71bb991a91d5a55f77220ef5 -
Trigger Event:
push
-
Statement type: