mcpField
A
accessibility-testing

accessibility-testing

github.com/aj-geddes测试与质量374577 次安装34 周前更新
代码仓库

关于 accessibility-testing

这项技能帮助开发者测试 Web 应用的无障碍性,验证 WCAG 合规性及辅助技术的可用性。内容兼有自动化测试示例,以及键盘、屏幕阅读器和人工检查指南。

主要功能

  1. 01Playwright 与 axe-core 示例
  2. 02键盘导航测试
  3. 03屏幕阅读器兼容性检查
  4. 04ARIA 与表单无障碍检查
  5. 05Jest、Cypress 和 Selenium 指南

适用场景

  1. 01检查 WCAG 2.1/2.2 合规性
  2. 02发现键盘导航障碍
  3. 03检查对比度与 ARIA 属性
  4. 04在 CI 中加入自动化检查

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill accessibility-testing

安装后在 Claude Code 中输入/accessibility-testing确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
aria-testing.md
axe-core-with-playwright.md
cypress-accessibility-testing.md
jest-with-jest-axe.md
keyboard-navigation-testing.md
python-with-selenium-and-axe.md
scripts/
scaffold-tests.sh
templates/
test-template.js

详细介绍

无障碍测试

目录

概述

无障碍测试确保残障人士能够使用 Web 应用,包括使用屏幕阅读器、键盘导航或其他辅助技术的人士。它用于验证是否符合 WCAG(Web 内容无障碍指南),并识别无障碍障碍。

适用场景

  • 验证是否符合 WCAG 2.1/2.2
  • 测试键盘导航
  • 验证屏幕阅读器兼容性
  • 测试颜色对比度
  • 验证 ARIA 属性
  • 测试表单无障碍性
  • 确保焦点管理正常
  • 使用辅助技术进行测试

快速入门

最简可运行示例:

// tests/accessibility/homepage.a11y.test.ts
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

test.describe("Homepage Accessibility", () => {
  test("should not have any automatically detectable WCAG A or AA violations", async ({
    page,
  }) => {
    await page.goto("/");

    const accessibilityScanResults = await new AxeBuilder({ page })
      .withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
      .analyze();

    expect(accessibilityScanResults.violations).toEqual([]);
  });

  test("navigation should be accessible", async ({ page }) => {
    await page.goto("/");

    const results = await new AxeBuilder({ page }).include("nav").analyze();

    expect(results.violations).toEqual([]);
  });

// ... (see reference guides for full implementation)

参考指南

references/ 目录中的详细实现:

指南内容
使用 Playwright 的 axe-core使用 Playwright 的 axe-core
键盘导航测试键盘导航测试
ARIA 测试ARIA 测试
使用 jest-axe 的 Jest使用 jest-axe 的 Jest
Cypress 无障碍测试Cypress 无障碍测试
使用 Selenium 和 axe 的 Python使用 Selenium 和 axe 的 Python

最佳实践

✅ 应该
  • 使用真实的辅助技术进行测试
  • 考虑仅使用键盘的用户
  • 测试颜色对比度
  • 使用语义化 HTML
  • 提供文本替代内容
  • 使用屏幕阅读器进行测试
  • 在 CI 中运行自动化测试
  • 遵循 WCAG 2.1 AA 标准
❌ 不应该
  • 只依赖自动化测试(它们只能发现约 30-40% 的问题)
  • 只用颜色传达信息
  • 跳过键盘导航测试
  • 忘记管理动态内容中的焦点
  • 使用 div/span 实现交互元素
  • 使用 display:none 隐藏可聚焦内容
  • 忽视 ARIA 最佳实践
  • 跳过手动测试

评论

支持 Markdown