Files
cc-ci/tests/custom-html/playwright/test_browser_smoke.py
autonomic-bot bec92659b1 feat(2): Q0.3/Q1.1 — custom-html PARITY + functional + playwright (Phase 2)
- tests/custom-html/PARITY.md: parity mapping (health_check.py ported);
  recipe-specific tests recorded with rationale; backup data-integrity +
  playwright sections.
- tests/custom-html/functional/test_health_check.py: parity port of
  recipe-info/custom-html/tests/health_check.py — SOURCE comment included.
- tests/custom-html/functional/test_content_roundtrip.py: NEW recipe-specific —
  write a marker into the served volume, fetch over HTTPS, assert exact bytes.
- tests/custom-html/functional/test_content_type_header.py: NEW recipe-specific —
  prove nginx returns text/html for .html and text/plain for .txt (MIME mapping).
- tests/custom-html/playwright/test_browser_smoke.py: P6 browser smoke (renders
  HTML, no console errors). Standalone Phase-2 custom-stage version.

Verified cold on cc-ci (STAGES=install,custom): 5 assertions all PASS in one
run (install generic + install overlay + content roundtrip + content type +
health check + browser smoke), deploy-count=1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 04:40:12 +01:00

38 lines
1.9 KiB
Python

"""custom-html — Playwright UI flow (Phase 2 P6).
The recipe-maintainer corpus did not ship a Playwright test for custom-html — but plan §4.1 names
`playwright/` as the canonical home for browser flows where a recipe's core UX is a UI. custom-html
serves HTML; a browser-rendered fetch (vs raw HTTP) proves the page actually renders and any client-
side resources resolve. Distinct from `tests/custom-html/test_install.py` which runs Playwright as
part of the lifecycle INSTALL overlay; this file is the standalone Phase-2 custom-stage version, so a
later non-lifecycle browser flow (e.g. a content-management UI) has its home already.
"""
from __future__ import annotations
def test_browser_renders_html(live_app):
"""Browser-render the served root page and assert the HTML loads with no console errors."""
from playwright.sync_api import sync_playwright
url = f"https://{live_app}/"
with sync_playwright() as p:
browser = p.chromium.launch(args=["--no-sandbox"])
try:
context = browser.new_context(ignore_https_errors=True)
page = context.new_page()
console_errors: list[str] = []
page.on(
"console",
lambda msg: console_errors.append(msg.text) if msg.type == "error" else None,
)
resp = page.goto(url, wait_until="load", timeout=30_000)
assert resp is not None and resp.status == 200, f"page status {resp and resp.status}"
html = page.content()
assert "<html" in html.lower(), "page did not render an HTML document"
# nginx default page contains "nginx" in markup; either custom HTML or default works,
# but BOTH should be served as actual HTML — caught above.
assert not console_errors, f"browser logged console errors: {console_errors}"
finally:
browser.close()