import { chromium } from 'playwright'; import AxeBuilder from '@axe-core/playwright'; import assert from 'node:assert/strict'; import { mkdir, writeFile } from 'node:fs/promises'; const origin = process.env.CMS_URL || 'http://127.0.0.1:8080'; const browser = await chromium.launch(); await mkdir('reports', { recursive: true }); const results = []; try { for (const width of [1440, 390]) { const context = await browser.newContext({ viewport: { width, height: 1000 } }); const page = await context.newPage(); const errors = []; page.on('pageerror', error => errors.push(error.message)); for (const path of ['/', '/grundlagen', '/projektstand']) { const response = await page.goto(origin + path); assert.equal(response.status(), 200); assert.equal(await page.locator('h1').count(), 1); assert.equal(await page.locator('script').count(), 0); assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), 'Horizontal overflow'); const axe = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21aa', 'best-practice']).analyze(); assert.deepEqual(axe.violations.map(v => ({ id: v.id, nodes: v.nodes.map(n => n.target) })), []); results.push({ width, path, violations: axe.violations.length, checks: axe.passes.length }); await page.screenshot({ path: `reports/${width}-${path === '/' ? 'home' : path.slice(1)}.png`, fullPage: true }); } await page.goto(origin); await page.keyboard.press('Tab'); assert.equal(await page.locator(':focus').innerText(), 'Zum Inhalt springen'); await page.keyboard.press('Enter'); assert.equal(await page.locator(':focus').getAttribute('id'), 'main'); await page.getByRole('link', { name: 'Die Grundlage entdecken' }).click(); assert.equal(new URL(page.url()).pathname, '/grundlagen'); await page.getByRole('link', { name: 'Projektstand' }).click(); assert.equal(new URL(page.url()).pathname, '/projektstand'); assert.deepEqual(errors, []); await context.close(); } const noJs = await browser.newPage({ javaScriptEnabled: false }); await noJs.goto(origin); assert.match(await noJs.locator('h1').innerText(), /Deine Inhalte/); await noJs.getByRole('link', { name: 'Die Grundlage entdecken' }).click(); assert.equal(new URL(noJs.url()).pathname, '/grundlagen'); await writeFile('reports/browser.json', JSON.stringify({ origin, results, keyboard: 'passed', noJavaScript: 'passed' }, null, 2)); console.log('Passed: 6 page/viewport accessibility checks, keyboard navigation, no-JS navigation.'); } finally { await browser.close(); }