|
| 1 | +name: Website E2E & Responsive Tests |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [main] |
| 5 | + pull_request: |
| 6 | + branches: [main] |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + responsive-tests: |
| 11 | + name: Responsive Layout Tests (Playwright) |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Setup Node.js |
| 17 | + uses: actions/setup-node@v4 |
| 18 | + with: |
| 19 | + node-version: 20 |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + npm install playwright @playwright/test http-server |
| 24 | + npx playwright install chromium --with-deps |
| 25 | +
|
| 26 | + - name: Start local server |
| 27 | + run: | |
| 28 | + npx http-server . -p 8080 -s & |
| 29 | + sleep 3 |
| 30 | +
|
| 31 | + - name: Run Responsive Tests |
| 32 | + run: npx playwright test tests/ --reporter=list |
| 33 | + env: |
| 34 | + BASE_URL: http://localhost:8080 |
| 35 | + |
| 36 | + - name: Upload Screenshots |
| 37 | + if: always() |
| 38 | + uses: actions/upload-artifact@v4 |
| 39 | + with: |
| 40 | + name: responsive-screenshots |
| 41 | + path: tests/screenshots/ |
| 42 | + |
| 43 | + - name: Upload Test Report |
| 44 | + if: always() |
| 45 | + uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: playwright-report |
| 48 | + path: playwright-report/ |
| 49 | + |
| 50 | + visual-diff: |
| 51 | + name: Visual Sanity (Screenshot Comparison) |
| 52 | + runs-on: ubuntu-latest |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Setup Node.js |
| 57 | + uses: actions/setup-node@v4 |
| 58 | + with: |
| 59 | + node-version: 20 |
| 60 | + |
| 61 | + - name: Install dependencies |
| 62 | + run: | |
| 63 | + npm install playwright @playwright/test http-server |
| 64 | + npx playwright install chromium --with-deps |
| 65 | +
|
| 66 | + - name: Start local server |
| 67 | + run: | |
| 68 | + npx http-server . -p 8080 -s & |
| 69 | + sleep 3 |
| 70 | +
|
| 71 | + - name: Capture Screenshots (Mobile + Desktop) |
| 72 | + run: | |
| 73 | + node << 'JSEOF' |
| 74 | + const { chromium } = require('playwright'); |
| 75 | + const fs = require('fs'); |
| 76 | + const path = require('path'); |
| 77 | +
|
| 78 | + const viewports = { |
| 79 | + 'mobile-375': { width: 375, height: 812 }, |
| 80 | + 'mobile-414': { width: 414, height: 896 }, |
| 81 | + 'tablet-768': { width: 768, height: 1024 }, |
| 82 | + 'desktop-1280': { width: 1280, height: 800 }, |
| 83 | + 'desktop-1920': { width: 1920, height: 1080 }, |
| 84 | + }; |
| 85 | +
|
| 86 | + const pages = [ |
| 87 | + { name: 'home', path: '/index.html' }, |
| 88 | + { name: 'get-started', path: '/getting-started.html' }, |
| 89 | + { name: 'docs', path: '/docs/index.html' }, |
| 90 | + { name: 'flow', path: '/flow.html' }, |
| 91 | + { name: 'kids', path: '/kids.html' }, |
| 92 | + { name: 'hardware-lab', path: '/hardware-lab.html' }, |
| 93 | + ]; |
| 94 | +
|
| 95 | + (async () => { |
| 96 | + const dir = 'tests/screenshots'; |
| 97 | + fs.mkdirSync(dir, { recursive: true }); |
| 98 | +
|
| 99 | + const browser = await chromium.launch(); |
| 100 | + let failures = []; |
| 101 | +
|
| 102 | + for (const [vpName, vpSize] of Object.entries(viewports)) { |
| 103 | + for (const page of pages) { |
| 104 | + const ctx = await browser.newContext({ viewport: vpSize }); |
| 105 | + const p = await ctx.newPage(); |
| 106 | + const url = `http://localhost:8080${page.path}`; |
| 107 | +
|
| 108 | + try { |
| 109 | + await p.goto(url, { waitUntil: 'networkidle', timeout: 15000 }); |
| 110 | + await p.waitForTimeout(500); |
| 111 | +
|
| 112 | + const fname = `${page.name}-${vpName}.png`; |
| 113 | + await p.screenshot({ path: path.join(dir, fname), fullPage: true }); |
| 114 | + console.log(` OK: ${fname}`); |
| 115 | +
|
| 116 | + // Check for horizontal overflow (mobile-breaking bug) |
| 117 | + const hasOverflow = await p.evaluate(() => { |
| 118 | + return document.documentElement.scrollWidth > document.documentElement.clientWidth + 5; |
| 119 | + }); |
| 120 | + if (hasOverflow && vpSize.width <= 768) { |
| 121 | + failures.push(`${page.name} at ${vpName}: horizontal overflow detected (content wider than viewport)`); |
| 122 | + } |
| 123 | +
|
| 124 | + // Check hero text is visible |
| 125 | + const heroVisible = await p.evaluate(() => { |
| 126 | + const h1 = document.querySelector('h1'); |
| 127 | + if (!h1) return true; |
| 128 | + const rect = h1.getBoundingClientRect(); |
| 129 | + return rect.width > 0 && rect.height > 0; |
| 130 | + }); |
| 131 | + if (!heroVisible) { |
| 132 | + failures.push(`${page.name} at ${vpName}: h1 not visible`); |
| 133 | + } |
| 134 | +
|
| 135 | + } catch (err) { |
| 136 | + failures.push(`${page.name} at ${vpName}: page load failed (${err.message})`); |
| 137 | + } |
| 138 | + await ctx.close(); |
| 139 | + } |
| 140 | + } |
| 141 | +
|
| 142 | + await browser.close(); |
| 143 | +
|
| 144 | + console.log('\n========================================'); |
| 145 | + if (failures.length > 0) { |
| 146 | + console.log('VISUAL SANITY FAILURES:'); |
| 147 | + failures.forEach(f => console.log(` FAIL: ${f}`)); |
| 148 | + process.exit(1); |
| 149 | + } else { |
| 150 | + console.log('All visual sanity checks passed'); |
| 151 | + console.log(`${Object.keys(viewports).length} viewports x ${pages.length} pages = ${Object.keys(viewports).length * pages.length} screenshots`); |
| 152 | + } |
| 153 | + })(); |
| 154 | + JSEOF |
| 155 | +
|
| 156 | + - name: Upload Screenshots |
| 157 | + if: always() |
| 158 | + uses: actions/upload-artifact@v4 |
| 159 | + with: |
| 160 | + name: visual-screenshots |
| 161 | + path: tests/screenshots/ |
0 commit comments