feat: add comprehensive Playwright E2E test suite
- Create e2e/ directory with 7 test modules covering: - Home page: title, nav links, theme toggle, newsletter form - Cookie consent: accept all, reject all, granular prefs, persistence - Article index: loads, tag filter, click-through navigation - Article detail: title/read-time, share section, comments, newsletter aside, related - Comments: valid submit → redirect, empty body → error display, disabled check - Newsletter: JS confirmation message, invalid email error, aside form, duplicate - Feeds: RSS/sitemap/robots.txt validity, tag feed, seeded content present - Extend seed_e2e_content management command with tagged article, about page, no-comments article, and legal pages for richer test coverage - Add seed command tests (create + idempotency) to keep coverage ≥ 90% - Add pr-e2e CI job (runs on pull_request): builds image, starts postgres + app, installs playwright, runs pytest e2e/ - Update nightly-e2e to run full e2e/ suite alongside legacy journey test - Add --ignore=e2e to unit-test pytest step (coverage must not include browser tests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
40
e2e/conftest.py
Normal file
40
e2e/conftest.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""Shared fixtures for E2E Playwright tests.
|
||||
|
||||
All tests in this directory require a running application server pointed to by
|
||||
the E2E_BASE_URL environment variable. Tests are automatically skipped when
|
||||
the variable is absent, making them safe to collect in any environment.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from collections.abc import Generator
|
||||
|
||||
import pytest
|
||||
from playwright.sync_api import Browser, BrowserContext, Page, sync_playwright
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def base_url() -> str:
|
||||
url = os.getenv("E2E_BASE_URL", "").rstrip("/")
|
||||
if not url:
|
||||
pytest.skip("E2E_BASE_URL not set – start a server and export E2E_BASE_URL to run E2E tests")
|
||||
return url
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def _browser(base_url: str) -> Generator[Browser, None, None]: # noqa: ARG001
|
||||
"""Session-scoped Chromium instance (headless)."""
|
||||
with sync_playwright() as pw:
|
||||
browser = pw.chromium.launch(headless=True)
|
||||
yield browser
|
||||
browser.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def page(_browser: Browser) -> Generator[Page, None, None]:
|
||||
"""Fresh browser context + page per test — no shared state between tests."""
|
||||
ctx: BrowserContext = _browser.new_context()
|
||||
pg: Page = ctx.new_page()
|
||||
yield pg
|
||||
ctx.close()
|
||||
Reference in New Issue
Block a user