playwright-php/accessibility

Accessibility testing for Playwright PHP using axe-core. Check web pages for WCAG compliance.

Maintainers

Package info

github.com/playwright-php/accessibility

Homepage

pkg:composer/playwright-php/accessibility

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2025-11-08 13:43 UTC

This package is auto-updated.

Last update: 2026-08-13 03:42:04 UTC


README

Playwright PHP

  PHP Version   CI   Release   License

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.