"""Read-only accessibility checks against representative production admin pages.""" import json import re from pathlib import Path from playwright.sync_api import sync_playwright ROOT = Path(__file__).resolve().parents[1] OUT = ROOT / 'artifacts/platform-upgrade' credentials = re.search(r'`([^`]+)` / `([^`]+)`', (ROOT / 'apps/com/admin/README.md').read_text(encoding='utf-8')) report = [] with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page(viewport={'width': 1440, 'height': 1000}) page.goto('https://admin.nomadro.com/login') page.locator('input[autocomplete=username]').fill(credentials[1]) page.locator('input[autocomplete=current-password]').fill(credentials[2]) page.locator('button[type=submit]').click() page.wait_for_url(re.compile(r'.*/(cn|intl)/social/overview')) for route in ['social/overview', 'switches', 'orders', 'users', 'events', 'ntfy', 'audience', 'social/catalog', 'operations', 'blog']: for theme in ['dark', 'light']: page.goto('https://admin.nomadro.com/intl/' + route, wait_until='domcontentloaded') page.locator('.com-page').wait_for() page.wait_for_timeout(900) page.evaluate('(theme) => document.documentElement.setAttribute("data-theme", theme)', theme) page.wait_for_timeout(250) page.add_script_tag(path=str(OUT / 'axe.min.js')) violations = page.evaluate('''async () => (await axe.run(document, {runOnly:{type:'tag',values:['wcag2a','wcag2aa','wcag21aa']}})).violations.map(v => ({id:v.id,impact:v.impact,description:v.description,nodes:v.nodes.map(n => ({target:n.target,summary:n.failureSummary}))}))''') report.append({'route': route, 'theme': theme, 'violations': violations}) browser.close() (OUT / 'admin-accessibility.json').write_text(json.dumps(report, indent=2), encoding='utf-8') print(json.dumps({'pagesAndThemes': len(report), 'violations': [{'route': row['route'], 'theme': row['theme'], 'ids': [v['id'] for v in row['violations']]} for row in report if row['violations']]}))