בדיקה
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אחת הדרכים החשובות לבדוק את הנגישות היא בדיקה ידנית: מפעילים את שירותי הנגישות, כמו TalkBack או גישה באמצעות מתג, ובודקים אם הכל פועל כצפוי. כך תוכלו לקבל תובנות ישירות לגבי חוויית השימוש של משתמשים עם צרכים של נגישות באפליקציה.
בנוסף לאימות ידני, כדאי להשתמש גם בבדיקות אוטומטיות כדי לסמן בעיות פוטנציאליות שעלולות להשפיע על חוויית המשתמש בזמן שאתם מבצעים שינויים באפליקציה.
ממשקי ה-API הקיימים לבדיקת Compose מאפשרים לכתוב בדיקות אוטומטיות שמקיימות אינטראקציה עם רכיבים סמנטיים, ולטעון את המאפיינים שהוגדרו בממשק המשתמש.
בדיקות נגישות
לבדיקות נגישות אוטומטיות, אפשר גם להשתמש ב-Accessibility Test Framework – אותה מסגרת בסיסית שמפעילה את Accessibility Scanner ואת בדיקות הנגישות ב-Espresso – כדי לבצע באופן אוטומטי בדיקות מסוימות שקשורות לנגישות, החל מגרסה 1.8.0 של Compose.
כדי להפעיל את הבדיקות, מוסיפים את התלות ui-test-junit4-accessibility
, קוראים ל-enableAccessibilityChecks()
ב-AndroidComposeTestRule
ומפעילים פעולה או tryPerformAccessibilityChecks
:
@Rule
@JvmField
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun noAccessibilityLabel() {
composeTestRule.setContent {
Box(
modifier = Modifier
.size(50.dp, 50.dp)
.background(color = Color.Gray)
.clickable { }
.semantics {
contentDescription = ""
}
)
}
composeTestRule.enableAccessibilityChecks()
// Any action (such as performClick) will perform accessibility checks too:
composeTestRule.onRoot().tryPerformAccessibilityChecks()
}
הבדיקה הספציפית הזו נכשלת עם חריג והודעה על כך שאולי אין לפריט תווית ששירותי הנגישות יכולים לקרוא.
בדיקות אחרות שזמינות מחפשות בעיות נגישות שקשורות לניגודיות צבעים, לגודל קטן של יעד מגע או לסדר הסריקה של רכיבים.
אם אתם משלבים תצוגות עם Compose, ואתם כבר משתמשים ב-AccessibilityValidator
או צריכים להגדיר אותו, תוכלו להגדיר אותו בכלל:
@Test
fun lowContrastScreen() {
composeTestRule.setContent {
Box(
modifier = Modifier
.fillMaxSize()
.background(color = Color(0xFFFAFBFC)),
contentAlignment = Alignment.Center
) {
Text(text = "Hello", color = Color(0xFFB0B1B2))
}
}
// Optionally, set AccessibilityValidator manually
val accessibilityValidator = AccessibilityValidator()
.setThrowExceptionFor(
AccessibilityCheckResult.AccessibilityCheckResultType.WARNING
)
composeTestRule.enableAccessibilityChecks(accessibilityValidator)
composeTestRule.onRoot().tryPerformAccessibilityChecks()
}
בשילוב עם בדיקות ידניות, בדיקות אוטומטיות שמשתמשות גם ב-Compose APIs וגם במסגרת הבדיקה של הנגישות יכולות לעזור לכם לזהות בעיות אפשריות בשלב מוקדם בתהליך הפיתוח.
מומלץ עבורך
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-23 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-23 (שעון UTC)."],[],[],null,["# Testing\n\nAn essential way of testing accessibility is a form of manual testing: by\nturning accessibility services, like TalkBack or Switch Access, on, and checking\nif everything works as expected. This provides direct insight into how users\nwith accessibility needs might experience your application.\n\nIn conjunction with manual verification, you should also use automated testing\nto flag any potential issues that could impact user experience as you make\ncontinual changes to your app.\n\n[Existing Compose testing APIs](/develop/ui/compose/testing) allow you to write automated tests that\ninteract with semantic elements and to [assert the properties](/develop/ui/compose/testing/apis#assertions) defined in\nyour UI.\n\nAccessibility checks\n--------------------\n\nFor automated accessibility testing, you can also use the\n[Accessibility Test Framework](https://github.com/google/Accessibility-Test-Framework-for-Android)---the same underlying framework that powers\nAccessibility Scanner and accessibility checks in Espresso---to perform some\naccessibility-related checks automatically, starting with Compose 1.8.0.\n\nTo enable the checks, add the `ui-test-junit4-accessibility` dependency,\ncall [`enableAccessibilityChecks()`](/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#(androidx.compose.ui.test.ComposeUiTest).enableAccessibilityChecks(com.google.android.apps.common.testing.accessibility.framework.integrations.espresso.AccessibilityValidator)) in the [`AndroidComposeTestRule`](/reference/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule),\nand trigger an action or [`tryPerformAccessibilityChecks`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-test/src/androidMain/kotlin/androidx/compose/ui/test/Actions.android.kt;drc=808c430f1ac6028d33902e3d685720f2b96f7aee;l=27):\n\n\n```kotlin\n@Rule\n@JvmField\nval composeTestRule = createAndroidComposeRule\u003cComponentActivity\u003e()\n\n@Test\nfun noAccessibilityLabel() {\n composeTestRule.setContent {\n Box(\n modifier = Modifier\n .size(50.dp, 50.dp)\n .background(color = Color.Gray)\n .clickable { }\n .semantics {\n contentDescription = \"\"\n }\n )\n }\n\n composeTestRule.enableAccessibilityChecks()\n\n // Any action (such as performClick) will perform accessibility checks too:\n composeTestRule.onRoot().tryPerformAccessibilityChecks()\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/androidTest/java/com/example/compose/snippets/accessibility/AccessibilitySnippets.kt#L49-L71\n```\n\n\u003cbr /\u003e\n\nThis specific test fails with an exception and a message that the item may not\nhave a label readable by accessibility services.\n\nOther available checks look for accessibility issues with color contrast,\nsmall touch target size, or elements' traversal order.\n\nIf you're mixing Views with Compose and you're already using an\n`AccessibilityValidator`, or you need to configure one, you can set it in the\nrule:\n\n\n```kotlin\n@Test\nfun lowContrastScreen() {\n composeTestRule.setContent {\n Box(\n modifier = Modifier\n .fillMaxSize()\n .background(color = Color(0xFFFAFBFC)),\n contentAlignment = Alignment.Center\n ) {\n Text(text = \"Hello\", color = Color(0xFFB0B1B2))\n }\n }\n\n // Optionally, set AccessibilityValidator manually\n val accessibilityValidator = AccessibilityValidator()\n .setThrowExceptionFor(\n AccessibilityCheckResult.AccessibilityCheckResultType.WARNING\n )\n\n composeTestRule.enableAccessibilityChecks(accessibilityValidator)\n\n composeTestRule.onRoot().tryPerformAccessibilityChecks()\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/androidTest/java/com/example/compose/snippets/accessibility/AccessibilitySnippets.kt#L94-L116\n```\n\n\u003cbr /\u003e\n\nIn combination with manual testing, automated tests using both Compose APIs as\nwell as the Accessibility Test Framework can help you detect possible problems\nearly on in the development process.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Accessibility in Compose](/develop/ui/compose/testing)\n- \\[Material Design 2 in Compose\\]\\[19\\]\n- [Testing your Compose layout](/develop/ui/compose/testing/apis#assertions)"]]