Skip to content

playwright-php/accessibility

Repository files navigation

Playwright PHP

  PHP Version   CI   Release   License

Playwright PHP - Accessibility

Perform real accessibility audits on web pages using Playwright PHP and axe-core,
checking for WCAG, ARIA, color contrast, and best-practice compliance.

Installation

This package relies on Playwright PHP - to install it, follow the instructions in Playwright PHP’s installation guide.

composer require --dev playwright-php/accessibility

Usage

Basic Analysis

use Playwright\Accessibility\AxeBuilder; $builder = new AxeBuilder($page); $results = $builder->analyze(); if ($results->hasViolations()) { foreach ($results->violations as $violation) { echo "{$violation->id}: {$violation->help}\n"; } }

PHPUnit Integration

use Playwright\Accessibility\AssertsAccessibility; class MyTest extends TestCase { use AssertsAccessibility; public function testPageIsAccessible(): void { $page->goto('https://example.com'); $this->assertIsAccessible($page); } }

Advanced Configuration

// Scope to specific regions $builder->within('#main-content')->analyze(); // Filter by WCAG level $builder->withTags([WcagTag::WCAG_2_1_AA])->analyze(); // Disable specific rules $builder->withoutRules([RuleId::COLOR_CONTRAST])->analyze(); // Exclude elements $builder->exclude('.advertisement')->analyze();

License

This package is released by the Playwright PHP project under the MIT License. See the LICENSE file for details.

Sponsor this project

 

Contributors