playwright-php / accessibility
Accessibility testing for Playwright PHP using axe-core. Check web pages for WCAG compliance.
Fund package maintenance!
Requires
- php: ^8.2
- playwright-php/playwright: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.40
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.3
This package is auto-updated.
Last update: 2026-08-13 03:42:04 UTC
README
Playwright PHP Accessibility
Run axe-core checks in pages controlled by Playwright PHP, inspect the results as PHP objects, or fail PHPUnit tests when violations are found.
Installation
The package requires PHP 8.2 or later and Playwright PHP 1.x.
composer require --dev playwright-php/accessibility vendor/bin/playwright-install --browsers
Quick Start
Use the PHPUnit trait with Playwright PHP's test case:
<?php use Playwright\Accessibility\AssertsAccessibility; use Playwright\Testing\PlaywrightTestCase; final class AccessibilityTest extends PlaywrightTestCase { use AssertsAccessibility; public function test_homepage_has_no_detected_violations(): void { $this->page->goto('https://example.com'); $this->assertIsAccessible($this->page); } }
Configuring an Audit
AxeBuilder can limit the scan to a region, select standards, exclude elements,
or disable rules:
use Playwright\Accessibility\AxeBuilder; use Playwright\Accessibility\RuleId; use Playwright\Accessibility\WcagTag; $results = (new AxeBuilder($page)) ->within('#main-content') ->exclude('.third-party-widget') ->withTags([WcagTag::WCAG_2_1_AA]) ->withoutRules([RuleId::COLOR_CONTRAST]) ->analyze(); foreach ($results->violations as $violation) { echo $violation->id.': '.$violation->help.PHP_EOL; }
assertIsAccessible() accepts a page, a configured builder, or an existing
result object.
Limits
Automated axe checks detect only part of the accessibility problems a user may encounter. A passing result does not establish WCAG conformance and does not replace keyboard, screen-reader, zoom, motion, or usability testing.
The audit covers the page state at the time it runs. Navigate, authenticate, open dialogs, and trigger dynamic states before making the assertion.
Documentation
Contributing
Install dependencies and browsers, then run code style, static analysis, and the test suite:
composer install vendor/bin/playwright-install --browsers vendor/bin/php-cs-fixer fix --dry-run --diff vendor/bin/phpstan analyse --memory-limit=-1 vendor/bin/phpunit
License
This package is released under the MIT License.