Run axe-core checks in pages controlled by Playwright PHP, inspect the results as PHP objects, or fail PHPUnit tests when violations are found.
The package requires PHP 8.2 or later and Playwright PHP 1.x.
composer require --dev playwright-php/accessibility
vendor/bin/playwright-install --browsersUse 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);
}
}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.
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.
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/phpunitThis package is released under the MIT License.
