Android Jetpack Compose UI testing: equivalent of espresso clearFocus()?
13:56 20 Nov 2025

It is common to test inline errors by filling out a textfield and then clearing focus, as the validation happens after the user is done with it. In espresso that can look like:

onView(allOf(isAssignableFrom(EditText::class.java), withId(fieldViewId)))
    .perform(safeScrollTo(), typeText(text), pressImeActionButton(), clearFocus())

And the equivalent of filling out the field in Compose can look like:

composeTestRule.onNodeWithTag(tag).assert(hasSetTextAction()).performTextInput(text)

How can I then clear the focus?

android android-jetpack-compose gui-testing