Skip to content

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

License

Notifications You must be signed in to change notification settings

playwright-php/accessibility

Repository files navigation

Playwright PHP

  PHP Version   CI   Release   License

Playwright PHP - Accessibility

Important

This package is experimental. Its API may still change before the upcoming 1.0 release.

Curious or interested? Try it out, share your feedback, or ideas!

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.

Releases

No releases published

Sponsor this project