Enabling Accessibility Checks 标志

Enabling Accessibility Checks

社区
skydoves
enabling-accessibility-checks

Use this skill to enable Espresso's `AccessibilityValidator` against the Compose semantics tree via `enableAccessibilityChecks(...)` from `androidx.compose.ui:ui-test-accessibility` (for `ComposeUiTest`) or `androidx.compose.ui:ui-test-junit4-accessibility` (for `ComposeTestRule` / `AndroidComposeTestRule`). Covers the API surface, the auto-check after every UI-mutating action (`performMultiModalInput` is the lone exception), the manual `tryPerformAccessibilityChecks()` entry point, sharing the validator with Espresso via `AccessibilityChecks.enable()`, the API 34+ requirement, and the Robolectric inconclusive behavior (logs a `Log.w` warning and still installs the validator, but Robolectric does not faithfully drive accessibility services — b/332778271). Use when the developer asks "how do I enable a11y checks in a Compose test", "AccessibilityChecks.enable", "AccessibilityValidator throws on click", "robolectric a11y not supported", or "ComposeTestRule IllegalStateException".

概览

发布者skydoves
代码仓库android-testing-skills
技能名称enabling-accessibility-checks
星标数
338
复刻数
14
附带文件
仅含指令
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 skydoves 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Enabling Accessibility Checks AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/skydoves/android-testing-skills/tree/main/compose/debug/enabling-accessibility-checks
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/skydoves/android-testing-skills.git /tmp/android-testing-skills
mkdir -p .claude/skills
cp -r /tmp/android-testing-skills/compose/debug/enabling-accessibility-checks .claude/skills/enabling-accessibility-checks
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Enabling Accessibility Checks,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Enabling Accessibility Checks。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Enabling Accessibility Checks 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Enabling Accessibility Checks — Espresso's AccessibilityValidator on the Compose Tree

The Compose accessibility test artifacts wire Espresso's AccessibilityValidator (from com.google.android.apps.common.testing.accessibility.framework.integrations.espresso) into the Compose action pipeline. Once enabled, every action that mutates the UI (performClick, performScrollTo*, performTextInput, …) runs the validator against the underlying View first. Two distinct artifacts cover two test entry points (ComposeUiTest and ComposeTestRule), with one stable and one experimental. Real device + API 34+ for meaningful results — on Robolectric the validator is still installed but a Log.w warning is emitted and any pass is inconclusive (Robolectric does not faithfully drive the accessibility services).

When to use this skill

  • The developer is adding accessibility regression coverage to a Compose-only screen.
  • A reviewer asks for an a11y test that fails the build when contrast / touch-target / label rules regress.
  • The developer mentions "AccessibilityChecks.enable", "AccessibilityValidator", or "Compose accessibility validator".
  • A hybrid Compose + Views screen needs a single shared AccessibilityValidator between Espresso and Compose.
  • The developer's a11y check appears to do nothing on Robolectric (the Log.w warning explains why).

When NOT to use this skill

  • The check fails because of a bad finder, not an a11y violation. Use ../printing-the-semantics-tree/SKILL.md.
  • The test runs on Robolectric (host JVM). Cited limitation at compose/ui/ui-test-accessibility/src/androidMain/kotlin/androidx/compose/ui/test/accessibility/ComposeUiTestExt.android.kt:50-53. Move the test to androidDeviceTest and a real device API 34+ — see ../../setup/setting-up-host-vs-device-tests/SKILL.md.
  • The test target API is below 34. The annotation @RequiresApi(34) makes calls fail to compile on lower minSdk. Use @SdkSuppress(minSdkVersion = 34) on the test method and skip on older devices.
  • The user wants semantics test coverage (roles, content descriptions, click actions). Use ../../assertions/asserting-node-state-and-text/SKILL.md.

Prerequisites

  • Real Android device (or emulator) running API 34+ (Android U).
  • One of:
    • androidx.compose.ui:ui-test-accessibility on androidTestImplementation — extends ComposeUiTest. @RequiresApi(34) @ExperimentalTestApi. Needs @OptIn(ExperimentalTestApi::class).
    • androidx.compose.ui:ui-test-junit4-accessibility on androidTestImplementation — extends AndroidComposeTestRule and ComposeTestRule. @RequiresApi(34) only — NOT experimental.
  • The test class skeleton from ../../patterns/structuring-a-compose-test/SKILL.md.

Workflow

  • 1. Enable checks once per test (or in @Before). API for AndroidComposeTestRule:
kotlin
import androidx.compose.ui.test.junit4.accessibility.enableAccessibilityChecks
import com.google.android.apps.common.testing.accessibility.framework.integrations.espresso.AccessibilityValidator

@Before
fun before() {
    rule.enableAccessibilityChecks()      // default: AccessibilityValidator().setRunChecksFromRootView(true)
}

Default-validator signature, cited at compose/ui/ui-test-junit4-accessibility/src/androidMain/kotlin/androidx/compose/ui/test/junit4/accessibility/AndroidComposeTestRuleExt.android.kt:44-49:

kotlin
@RequiresApi(34)
public fun <R : TestRule, A : ComponentActivity> AndroidComposeTestRule<R, A>.enableAccessibilityChecks(
    accessibilityValidator: AccessibilityValidator =
        AccessibilityValidator().setRunChecksFromRootView(true),
)

For ComposeUiTest (e.g. inside runComposeUiTest { }), the equivalent lives in androidx.compose.ui.test.accessibility and requires @OptIn(ExperimentalTestApi::class):

kotlin
@OptIn(ExperimentalTestApi::class)
@Test
fun runs() = runAndroidComposeUiTest<ComponentActivity> {
    enableAccessibilityChecks()
    onNodeWithText("Submit").performClick()
}

Cited from compose/ui/ui-test-accessibility/samples/src/main/java/androidx/compose/ui/test/accessibility/samples/AccessibilityChecksSamples.kt:42-61.

  • 2. Configure stricter modes via the AccessibilityValidator itself. Pass a custom validator to flip the threshold from WARNING-only to ERROR.
kotlin
val validator = AccessibilityValidator().apply {
    setThrowExceptionFor(AccessibilityCheckResultType.ERROR)
}
rule.enableAccessibilityChecks(validator)

Cited from AccessibilityChecksSamples.kt:68-82.

  • 3. Auto-checks fire before every UI-mutating action. Cited at compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Actions.kt:79, 160, 189, 236, 402, 451, 496, 535, 697, 780, 948 — tryPerformAccessibilityChecks() is invoked at the top of performClick, performScrollTo, performScrollToIndex/Key/Node, performTouchInput, performMouseInput, performKeyInput, performTrackpadInput, performRotaryScrollInput, performIndirectPointerInput, performFirstLinkClick, and the text-action family. performMultiModalInput does NOT auto-check (Actions.kt:582); the developer must call tryPerformAccessibilityChecks() explicitly. requestFocus() (Actions.kt:600-601) goes through performSemanticsAction and likewise does NOT auto-check — call tryPerformAccessibilityChecks() after focusing if accessibility coverage matters there.

  • 4. Run a check manually when needed (for performMultiModalInput, or to gate a phase).

kotlin
rule.onRoot().tryPerformAccessibilityChecks()

Cited from AccessibilityChecksSamples.kt:53.

  • 5. Share the validator with Espresso for hybrid Compose + View screens. AccessibilityChecks.enable() returns the same validator instance Espresso uses; pass it to Compose so both layers report against one configuration.
kotlin
import androidx.test.espresso.accessibility.AccessibilityChecks

@OptIn(ExperimentalTestApi::class)
@Test
fun hybrid() = runAndroidComposeUiTest<ComponentActivity> {
    val validator = AccessibilityChecks.enable()
    enableAccessibilityChecks(validator)
}

Cited from AccessibilityChecksSamples.kt:88-98.

  • 6. Disable checks when leaving an isolated phase.
kotlin
rule.disableAccessibilityChecks()

Cited at AndroidComposeTestRuleExt.android.kt:71-75.

  • 7. Use the ComposeTestRule overload only when the rule is concretely an AndroidComposeTestRule. Cited at compose/ui/ui-test-junit4-accessibility/src/androidMain/kotlin/androidx/compose/ui/test/junit4/accessibility/ComposeTestRuleExt.android.kt:38-49. Non-Android rules throw NotImplementedError:
text
Enabling accessibility checks is currently only supported for AndroidComposeTestRule.
If you have a custom ComposeTestRule implementation that wraps an AndroidComposeTestRule,
directly call enableAccessibilityChecks on the AndroidComposeTestRule instead

Patterns

Pattern: enabling on Robolectric — inconclusive results

kotlin
// WRONG (assertion is meaningless under Robolectric)
@Config(sdk = [34])
@RunWith(RobolectricTestRunner::class)
class MyA11yTest {
    @get:Rule val rule = createComposeRule(StandardTestDispatcher())

    @Test fun checks() {
        rule.enableAccessibilityChecks()                      // logs Log.w; validator IS installed
        rule.setContent { /* contrast violation */ }
        rule.onNodeWithTag("submit").performClick()           // may PASS, may FAIL — inconclusive
    }
}
// WRONG because: HasRobolectricFingerprint = (Build.FINGERPRINT.lowercase() == "robolectric")
// triggers a Log.w but the validator is STILL installed (ComposeUiTestExt.android.kt:50-61
// AND AndroidComposeTestRuleExt.android.kt:50-64). Robolectric does not faithfully drive
// the accessibility services, so any result is inconclusive. Tracking bug: b/332778271.
// Run accessibility checks ONLY on a real device API 34+ for trustworthy results.
kotlin
// RIGHT — move the test to androidDeviceTest and run on a real device API 34+
@MediumTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = 34)
class MyA11yTest {
    @get:Rule val rule = createComposeRule(StandardTestDispatcher())

    @Before fun before() { rule.enableAccessibilityChecks() }

    @Test fun submitPassesA11y() {
        rule.setContent { MyScreen() }
        rule.onNodeWithTag("submit").performClick()
    }
}

Pattern: performMultiModalInput skips the auto-check

kotlin
// WRONG
@Test
fun multiModal() {
    rule.enableAccessibilityChecks()
    rule.setContent { MyScreen() }
    rule.onNodeWithTag("canvas").performMultiModalInput {
        touch { down(center); up() }
        key  { pressKey(Key.Enter) }
    }
    // No a11y check ran for this action — Actions.kt:582 omits tryPerformAccessibilityChecks().
}
kotlin
// RIGHT
@Test
fun multiModal() {
    rule.enableAccessibilityChecks()
    rule.setContent { MyScreen() }
    rule.onNodeWithTag("canvas").performMultiModalInput { … }
    rule.onRoot().tryPerformAccessibilityChecks()             // explicit
}

Pattern: ComposeTestRule (non-Android) overload throws

kotlin
// WRONG
val rule: ComposeTestRule = MyCustomRuleThatWrapsAndroid()
rule.enableAccessibilityChecks()                              // throws NotImplementedError
// WRONG because: only AndroidComposeTestRule is supported. Cited at
// ComposeTestRuleExt.android.kt:38-49.
kotlin
// RIGHT — call on the underlying AndroidComposeTestRule
val rule = AndroidComposeTestRule(/* … */)
rule.enableAccessibilityChecks()

Pattern: shared validator with Espresso

kotlin
// RIGHT
@OptIn(ExperimentalTestApi::class)
@Test
fun shared() = runAndroidComposeUiTest<ComponentActivity> {
    val validator = AccessibilityChecks.enable().apply {
        setThrowExceptionFor(AccessibilityCheckResultType.ERROR)
    }
    enableAccessibilityChecks(validator)
    onNodeWithText("Submit").performClick()
}

Mandatory rules

  • MUST target real device API 34+ for any test that calls enableAccessibilityChecks. MUST NOT rely on the check producing meaningful results under Robolectric — Build.FINGERPRINT.lowercase() == "robolectric" triggers Log.w("...", "Accessibility checks are currently not supported by Robolectric") (ComposeUiTestExt.android.kt:50-53, AndroidComposeTestRuleExt.android.kt:50-56), and the validator is still installed but cannot rely on the accessibility services Robolectric does not faithfully emulate. Treat any pass under Robolectric as inconclusive. Tracking bug: b/332778271.
  • MUST prefer androidx.compose.ui:ui-test-junit4-accessibility (stable) when the rule entry point is used; MUST apply @OptIn(ExperimentalTestApi::class) when using androidx.compose.ui:ui-test-accessibility against ComposeUiTest.
  • MUST call tryPerformAccessibilityChecks() manually after performMultiModalInput { … } and after requestFocus() if the test wants validation for those actions — Actions.kt:582 omits the auto-check for performMultiModalInput, and requestFocus() (Actions.kt:600-601) routes through performSemanticsAction which likewise does not auto-check.
  • MUST NOT call enableAccessibilityChecks on a ComposeTestRule that is not also an AndroidComposeTestRule. The non-Android overload throws NotImplementedError (ComposeTestRuleExt.android.kt:38-49).
  • PREFERRED: raise the threshold to AccessibilityCheckResultType.ERROR via AccessibilityValidator().setThrowExceptionFor(...) so violations fail the test instead of merely logging.
  • PREFERRED: in hybrid Compose + Views suites, share one AccessibilityValidator via AccessibilityChecks.enable() and pass it to both Espresso and Compose. Cited at AccessibilityChecksSamples.kt:88-98.

Verification

  • The test runs on real device API 34+. @SdkSuppress(minSdkVersion = 34) is present if the module's minSdk is lower.
  • No Robolectric Log.w warning "Accessibility checks are currently not supported by Robolectric" appears in test output.
  • The relevant artifact is on androidTestImplementation: androidx.compose.ui:ui-test-junit4-accessibility (rule path) or androidx.compose.ui:ui-test-accessibility + @OptIn(ExperimentalTestApi::class) (ComposeUiTest path).
  • enableAccessibilityChecks(...) is called once per test (or in @Before); disableAccessibilityChecks() is called only when intentionally suppressing checks.
  • Any performMultiModalInput { … } site is followed by an explicit rule.onRoot().tryPerformAccessibilityChecks().
  • Hybrid Compose+View suites obtain the validator via AccessibilityChecks.enable() and pass it to enableAccessibilityChecks(validator).
  • No enableAccessibilityChecks call is made on a non-AndroidComposeTestRule instance.

References

  • enableAccessibilityChecks (rule path): compose/ui/ui-test-junit4-accessibility/src/androidMain/kotlin/androidx/compose/ui/test/junit4/accessibility/AndroidComposeTestRuleExt.android.kt:44-75
  • ComposeTestRule overload — NotImplementedError: compose/ui/ui-test-junit4-accessibility/src/androidMain/kotlin/androidx/compose/ui/test/junit4/accessibility/ComposeTestRuleExt.android.kt:38-66
  • enableAccessibilityChecks (ComposeUiTest path): compose/ui/ui-test-accessibility/src/androidMain/kotlin/androidx/compose/ui/test/accessibility/ComposeUiTestExt.android.kt:44-77
  • Robolectric inconclusive behavior (warns + still installs validator): ComposeUiTestExt.android.kt:50-61, AndroidComposeTestRuleExt.android.kt:50-64, b/332778271
  • Auto-check call sites in Actions.kt: compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Actions.kt:79, 160, 189, 236, 402, 451, 496, 535, 582 (omitted), 697, 780, 948
  • Samples: compose/ui/ui-test-accessibility/samples/src/main/java/androidx/compose/ui/test/accessibility/samples/AccessibilityChecksSamples.kt:42-98
  • Espresso accessibility checks: https://developer.android.com/training/testing/espresso/accessibility-checking
  • Test for accessibility (Compose): https://developer.android.com/develop/ui/compose/accessibility/testing
  • Compose UI testing release notes: https://developer.android.com/jetpack/androidx/releases/compose-ui

常见问题

Enabling Accessibility Checks AI 技能有什么作用?

Use this skill to enable Espresso's `AccessibilityValidator` against the Compose semantics tree via `enableAccessibilityChecks(...)` from `androidx.compose.ui:ui-test-accessibility` (for `ComposeUiTest`) or `androidx.compose.ui:ui-test-junit4-accessibility` (for `ComposeTestRule` / `AndroidComposeTestRule`). Covers the API surface, the auto-check after every UI-mutating action (`performMultiModalInput` is the lone exception), the manual `tryPerformAccessibilityChecks()` entry point, sharing the validator with Espresso via `AccessibilityChecks.enable()`, the API 34+ requirement, and the Robo...

为什么在 TypingMind 中使用 Enabling Accessibility Checks?

因为您只需安装一次,就能搭配任何模型使用。Enabling Accessibility Checks 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Enabling Accessibility Checks?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/skydoves/android-testing-skills/tree/main/compose/debug/enabling-accessibility-checks。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Enabling Accessibility Checks?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Enabling Accessibility Checks 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Enabling Accessibility Checks 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Enabling Accessibility Checks AI 技能免费吗?

是的。skydoves 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇