Skip to content

Repository files navigation

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.

About

Accessibility audits in browser using Playwright PHP and axe-core: WCAG, ARIA, contrast ...

Topics

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages