PHP code example of playwright-php / accessibility

1. Go to this page and download the library: Download playwright-php/accessibility library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

playwright-php / accessibility example snippets




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);
    }
}

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;
}
bash
composer laywright-install --browsers