Collect playwright traces and make them available to CI logs

This commit is contained in:
Gael Goinvic committed 2026-10-09 08:51:54 +00:00
1 parent cff35d903a
commit fb204c0e0a
5 files changed
+41 -3

No files matched your search

+1
View File
@@ -10,3 +10,4 @@ __pycache__
charts/*/user_values/*.yaml
.pyhelm_cache
dist/
ess-helm-logs
+5
View File
@@ -170,6 +170,11 @@ No browser needs to be installed locally. The docker image is built on first use
Install the controller with `scripts/setup_playwright_controller.sh`, on every host (details in the
script). A plain `uv sync` removes the controller again: re-run the script afterwards. `uv run` keeps it.
Each browser test records a trace of what it did. The traces are written to
`ess-helm-logs/playwright-traces/<run timestamp>/`, next to the current working directory.
`collect-ess-logs` exports them with the other logs, so CI uploads them with the logs of the run.
View a trace with `playwright show-trace <file>` or by opening it on [trace.playwright.dev](https://trace.playwright.dev).
Pytest caches the namespace name and created user tokens between run. To start a run from scratch,
run `pytest-ess -- --cache-clear`.
+1
View File
@@ -0,0 +1 @@
Introduce basic end-to-end playwright tests.
+2 -1
View File
@@ -8,12 +8,13 @@ from .cluster import cert_manager, cluster, ess_namespace, helm_client, ingress,
from .data import ESSData, generated_data
from .helm import helm_prerequisites, ingress_ready, matrix_stack, secrets_generated
from .matrix_tools import build_matrix_tools, loaded_matrix_tools
from .playwright import browser, browser_page
from .playwright import browser, browser_page, browser_traces_run_dir
from .users import User, users
__all__ = [
"browser",
"browser_page",
"browser_traces_run_dir",
"build_matrix_tools",
"cert_manager",
"cluster",
+32 -2
View File
@@ -52,6 +52,11 @@ LAUNCH_CONFIG_ENV_VAR = "ESS_HELM_BROWSER_LAUNCH_CONFIG"
_WS_ENDPOINT_PATTERN = re.compile(r"ws://\S+:(?P<port>\d+)(?P<path>/\S*)")
_BROWSER_SERVER_STARTUP_TIMEOUT = 60
# The traces of the browser tests are written under this directory, next to the current
# working directory. collect-ess-logs exports this directory with the other logs, so CI
# uploads the traces with the logs of the run.
TRACES_DIR = Path("ess-helm-logs") / "playwright-traces"
def image_reference() -> str:
"""The name and tag of the docker image the browser runs in.
@@ -238,12 +243,37 @@ async def _wait_for_browser(playwright: Any, container: Container, container_ip:
)
@pytest.fixture(scope="session")
def browser_traces_run_dir() -> Path:
"""The directory the traces of this test run are written to.
CI runs the tests twice against the same cluster: once after a fresh deploy, once
after an upgrade. The timestamp keeps the traces of the two runs apart.
"""
return TRACES_DIR / time.strftime("%Y%m%d-%H%M%S")
def _trace_path(browser_traces_run_dir: Path, request: pytest.FixtureRequest) -> Path:
"""The trace file of a test, named after it. Characters that a file name cannot contain are replaced."""
test_id = re.sub(r"[^A-Za-z0-9._-]", "_", request.node.nodeid)
return browser_traces_run_dir / f"{test_id}.zip"
@pytest.fixture
async def browser_page(browser: Browser):
async def browser_page(browser: Browser, browser_traces_run_dir: Path, request: pytest.FixtureRequest):
# The browser knows the test CA (see the browser fixture). So it accepts the
# certificates of the ingress. The browser resolves the *.localhost names of the tests
# to the IP of the ingress (see the browser fixture).
context = await browser.new_context()
# Record what the test does in the browser. The trace shows it step by step, also
# after the run: view it with `playwright show-trace <file>` or on https://trace.playwright.dev.
await context.tracing.start(screenshots=True, snapshots=True, sources=True)
page = await context.new_page()
yield page
await context.close()
# Stopping the recording writes the trace file. The context must still be open then.
trace_path = _trace_path(browser_traces_run_dir, request)
trace_path.parent.mkdir(parents=True, exist_ok=True)
try:
await context.tracing.stop(path=trace_path)
finally:
await context.close()