Placing the keyboard focus on a specific view
As users can navigate your app using a keyboard (by pressing the TAB
key, for example), it may be desirable to place the keyboard focus on a specific View
prior to taking a screenshot.
See Support keyboard navigation for more information about keyboard navigation on Android.
In order to place the keyboard focus on a specific View
, configure the focusTargetId
property.
- ScreenshotTestRule
- ScreenshotScenarioRule
@ScreenshotInstrumentation
@Test
fun default() {
rule
.configure {
focusTargetId = R.id.fab
}
.assertSame()
}
@ScreenshotInstrumentation
@Test
fun default() {
launchActivity<TestHarnessActivity>().use { scenario ->
rule
.withScenario(scenario)
.configure {
focusTargetId = R.id.fab
}
.assertSame()
}
}