|
| 1 | +import { test, expect } from '@wordpress/e2e-test-utils-playwright'; |
| 2 | +const AxeBuilder = require( '@axe-core/playwright' ).default; |
| 3 | + |
| 4 | +test.describe( 'PHP Page Accessibility Tests', () => { |
| 5 | + test( 'should not have any automatically detectable accessibility violations', async ( { admin, page, requestUtils } ) => { |
| 6 | + |
| 7 | + // await requestUtils.login(); |
| 8 | + // await page.goto( 'http://localhost:8889/wp-admin/edit.php'); |
| 9 | + await admin.visitAdminPage( '/edit.php' ); |
| 10 | + |
| 11 | + // 2. Run the axe scan on the rendered page |
| 12 | + const scanResults = await new AxeBuilder({ page }).analyze(); |
| 13 | + |
| 14 | + // 3. Format and print violations individually if any are found |
| 15 | + if (scanResults.violations.length > 0) { |
| 16 | + console.log(`\n❌ Found ${scanResults.violations.length} accessibility violation(s):\n`); |
| 17 | + |
| 18 | + scanResults.violations.forEach((violation, index) => { |
| 19 | + console.log(`--- Violation #${index + 1} ---`); |
| 20 | + console.log(`Rule ID: ${violation.id}`); |
| 21 | + console.log(`Impact: ${violation.impact.toUpperCase()}`); |
| 22 | + console.log(`Failure: ${violation.description}`); |
| 23 | + console.log(`Help Link: ${violation.helpUrl}`); |
| 24 | + |
| 25 | + // List every specific HTML element failing this rule |
| 26 | + console.log('Failing Elements:'); |
| 27 | + violation.nodes.forEach((node) => { |
| 28 | + console.log(` - Target Selector: ${node.target.join(', ')}`); |
| 29 | + console.log(` HTML Snippet: ${node.html}`); |
| 30 | + }); |
| 31 | + console.log('\n'); |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + // 3. Assert that the violations list is empty |
| 36 | + expect(scanResults.violations).toEqual([]); |
| 37 | + }); |
| 38 | +}); |
0 commit comments