Playwright Testing Workflow for Documentation Deployment
Overview
This document describes the complete logical workflow for testing documentation sites using Playwright in containers (Docker/Podman) integrated with GitHub Pages deployment.
Architecture Diagram
┌─────────────────────────────────────────────────────────────────────┐
│ Developer Workflow │
└─────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────── ──┐
│ Step 1: Local Development & Testing │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 1. Edit documentation │ │
│ │ 2. Run local tests: │ │
│ │ - docker-compose up -d │ │
│ │ - npm run test:playwright │ │
│ │ 3. Validate links, accessibility, visual regression │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Step 2: Git Push → GitHub Actions CI/CD │
└─────────────────────────────────────────────────────────────────────┘
│
┌───────────────────┴───────────────────┐
▼ ▼
┌───────────────────────────────┐ ┌───────────────────────────────┐
│ Build Job │ │ Test Job (Playwright) │
│ ┌─────────────────────────┐ │ │ ┌─ ────────────────────────┐ │
│ │ 1. Checkout code │ │ │ │ 1. Start container │ │
│ │ 2. Install dependencies │ │ │ │ 2. Wait for health │ │
│ │ 3. Build SSG site │ │ │ │ 3. Run Playwright tests │ │
│ │ 4. Upload artifact │ │ │ │ - Link validation │ │
│ └─────────────────────────┘ │ │ │ - Accessibility │ │
└───────────────────────────────┘ │ │ - Visual regression │ │
│ │ - Navigation flow │ │
│ │ 4. Upload test results │ │
│ └─────────────────────────┘ │
└───────────────────────────────┘
│
▼
┌───────────────────────┐
│ Tests Pass? │
└───────────────────────┘
│
┌───────────────┴───────────────┐
│ YES │ NO
▼ ▼
┌─────────────────────────────────────────────────────┐ ┌────────────────┐
│ Step 3: Deploy to GitHub Pages │ │ Fail Pipeline │
│ ┌───────────────────────────────────────────────┐ │ │ Notify Team │
│ │ 1. Download build artifact │ │ └────────────────┘
│ │ 2. Deploy to gh-pages branch │ │
│ │ 3. GitHub Pages builds & serves │ │
│ └───────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Step 4: Post-Deployment Verification │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 1. Wait for GitHub Pages deployment │ │
│ │ 2. Run Playwright tests against LIVE site │ │
│ │ 3. Store results in Knowledge Graph │ │
│ │ 4. Update documentation health metrics │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
Detailed Workflow Stages
Stage 1: Local Development with Docker/Podman
Purpose: Test documentation in containerized environment before pushing
Tools:
- Docker or Podman
- Playwright
- SSG (Jekyll, Hugo, Docusaurus, etc.)
Commands:
# Start documentation container
docker-compose -f docker-compose.docs.yml up -d
# Wait for container health
docker-compose ps
# Run Playwright tests against container
npm run test:playwright:local
# Stop container
docker-compose down
What Gets Tested:
- Link Validation - All external and internal links
- Accessibility - WCAG compliance
- Navigation - All menu items work
- Search - Search functionality (if applicable)
- Visual Regression - Screenshots match baseline
Stage 2: CI/CD Pipeline (GitHub Actions)
Trigger: Push to main branch or Pull Request
Jobs:
Job 1: Build Documentation
build:
runs-on: ubuntu-latest
steps:
- Checkout code
- Setup SSG dependencies (Ruby/Node/Python)
- Build documentation site
- Upload build artifact
Job 2: Container Tests (Playwright)
test-container:
runs-on: ubuntu-latest
services:
docs:
image: documcp-docs:test
ports:
- 3001:3001
steps:
- Install Playwright
- Wait for container health
- Run Playwright test suite
- Upload test results & screenshots
Job 3: Deploy (Only on main branch, after tests pass)
deploy:
runs-on: ubuntu-latest
needs: [build, test-container]
if: github.ref == 'refs/heads/main'
steps:
- Download build artifact
- Deploy to GitHub Pages
Stage 3: Post-Deployment Verification
Purpose: Verify production site after GitHub Pages deployment
Process:
- Wait 2-5 minutes for GitHub Pages to deploy
- Run Playwright tests against live URL
- Store results in Knowledge Graph
- Update documentation health metrics
Knowledge Graph Integration:
{
type: "deployment_validation",
properties: {
url: "https://tosin2013.github.io/documcp/",
timestamp: "2025-01-15T10:30:00Z",
playwrightResults: {
totalTests: 25,
passed: 24,
failed: 1,
linksChecked: 127,
brokenLinks: 0,
accessibilityScore: 98,
},
healthScore: 96,
}
}
Container Setup with Playwright
Why Containers?
- Reproducibility - Same environment locally and in CI
- Isolation - No conflicts with system packages
- Speed - Pre-built images for faster testing
- Multi-SSG - Test different SSGs without installing all dependencies
Dockerfile with Playwright
# Multi-stage build for documentation testing
FROM mcr.microsoft.com/playwright:v1.55.1-focal AS playwright-base
# Stage 1: Build documentation
FROM node:20-alpine AS builder
WORKDIR /app
COPY docs ./docs/
COPY package*.json ./
RUN npm ci
RUN npm run docs:build
# Stage 2: Test with Playwright
FROM playwright-base AS tester
WORKDIR /app
COPY --from=builder /app/docs-site/build ./build
COPY playwright.config.ts ./
COPY tests/e2e ./tests/e2e
RUN npm install -D @playwright/test
# Browsers already installed in playwright-base
CMD ["npx", "playwright", "test"]
# Stage 3: Serve for local testing
FROM nginx:alpine AS server
COPY --from=builder /app/docs-site/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Docker Compose with Playwright
version: "3.8"
services:
# Documentation server
docs:
build:
context: .
dockerfile: Dockerfile.docs
target: server
ports:
- "3001:80"
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost/"]
interval: 5s
timeout: 3s
retries: 10
# Playwright test runner
playwright:
build:
context: .
dockerfile: Dockerfile.docs
target: tester
depends_on:
docs:
condition: service_healthy
environment:
- BASE_URL=http://docs
volumes:
- ./playwright-results:/app/test-results
- ./playwright-report:/app/playwright-report
command: npx playwright test --reporter=html