#!/bin/bash # TSYS Developer Support Stack - Browser (Playwright) Validation # Purpose: drive a real headless browser against every service to validate that # pages render and contain expected content. Deeper than HTTP probes: # it executes JavaScript, waits for DOM ready, and checks rendered text. # # Runs entirely inside the official Playwright Docker image (no host Node/npm # install required). All npm artefacts stay inside the container's own # filesystem, so no root-owned files are written to the host. Host services are # reached via the host network. # # Usage: ./tests/e2e/run-browser-tests.sh # Exit: 0 if all browser checks pass, 1 otherwise. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PLAYWRIGHT_IMAGE="mcr.microsoft.com/playwright:v1.52.0-noble" NETWORK_MODE="${PLAYWRIGHT_NETWORK:-host}" log() { echo "[browser-tests] $*"; } if ! docker info >/dev/null 2>&1; then echo "[ERROR] Docker is not running" >&2 exit 1 fi log "Ensuring Playwright image is present..." docker image inspect "$PLAYWRIGHT_IMAGE" >/dev/null 2>&1 || docker pull "$PLAYWRIGHT_IMAGE" log "Installing @playwright/test and running spec inside $PLAYWRIGHT_IMAGE..." # Mount the e2e sources read-only; copy them into a container-local work dir so # npm install never writes root-owned files to the host. docker run --rm \ ${NETWORK_MODE:+--network "$NETWORK_MODE"} \ -v "$SCRIPT_DIR":/src:ro \ --entrypoint sh \ "$PLAYWRIGHT_IMAGE" \ -c 'set -e; cp -r /src/. /work; cd /work; npm install --no-audit --no-fund; npx playwright test' log "Browser tests complete."