|
| 1 | +<div align="center"> |
| 2 | + <img src="https://github.com/playwright-php/.github/raw/main/profile/playwright-php.png" alt="Playwright PHP" /> |
| 3 | + |
| 4 | +  |
| 5 | +  |
| 6 | +  |
| 7 | +  |
| 8 | + |
| 9 | +</div> |
| 10 | + |
| 11 | +# Playwright PHP - Accessibility |
| 12 | + |
| 13 | +> [!IMPORTANT] |
| 14 | +> This package is **experimental**. Its API may still change before the upcoming `1.0` release. |
| 15 | +> |
| 16 | +> Curious or interested? Try it out, [share your feedback](https://github.com/playwright-php/accessibility/issues), or ideas! |
| 17 | +
|
| 18 | +Perform real **accessibility audits** on web pages using [Playwright PHP](https://github.com/playwright-php/playwright) and [axe-core](https://github.com/dequelabs/axe-core), |
| 19 | +checking for **WCAG**, **ARIA**, color contrast, and best-practice compliance. |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +This package relies on **Playwright PHP** - to install it, follow the instructions in [Playwright PHP’s installation guide](https://github.com/playwright-php/playwright#installation). |
| 24 | + |
| 25 | +```bash |
| 26 | +composer require --dev playwright-php/accessibility |
| 27 | +```` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### Basic Analysis |
| 32 | + |
| 33 | +```php |
| 34 | +use Playwright\Accessibility\AxeBuilder; |
| 35 | +
|
| 36 | +$builder = new AxeBuilder($page); |
| 37 | +$results = $builder->analyze(); |
| 38 | +
|
| 39 | +if ($results->hasViolations()) { |
| 40 | + foreach ($results->violations as $violation) { |
| 41 | + echo "{$violation->id}: {$violation->help}\n"; |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | +
|
| 46 | +### PHPUnit Integration |
| 47 | +
|
| 48 | +```php |
| 49 | +use Playwright\Accessibility\AssertsAccessibility; |
| 50 | +
|
| 51 | +class MyTest extends TestCase |
| 52 | +{ |
| 53 | + use AssertsAccessibility; |
| 54 | +
|
| 55 | + public function testPageIsAccessible(): void |
| 56 | + { |
| 57 | + $page->goto('https://example.com'); |
| 58 | + $this->assertIsAccessible($page); |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | +
|
| 63 | +### Advanced Configuration |
| 64 | +
|
| 65 | +```php |
| 66 | +// Scope to specific regions |
| 67 | +$builder->within('#main-content')->analyze(); |
| 68 | +
|
| 69 | +// Filter by WCAG level |
| 70 | +$builder->withTags([WcagTag::WCAG_2_1_AA])->analyze(); |
| 71 | +
|
| 72 | +// Disable specific rules |
| 73 | +$builder->withoutRules([RuleId::COLOR_CONTRAST])->analyze(); |
| 74 | +
|
| 75 | +// Exclude elements |
| 76 | +$builder->exclude('.advertisement')->analyze(); |
| 77 | +``` |
| 78 | +
|
| 79 | +## License |
| 80 | +
|
| 81 | +This package is released by the [Playwright PHP](https://playwright-php.dev) project |
| 82 | +under the **MIT License**. See the [LICENSE](LICENSE) file for details. |
0 commit comments