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?

1 Reply 1

In Jetpack Compas UI Testing, there isn't direct equivalent to Espresso’s clearFocus() built-in out of the box in the testing APIs.

Use .perfromImeAction()

If you are validation happen after the IME action (Done,Next,etc.),you can trigger that in your test::

composeTestRule.onNodeWithTag(tag)
    .performTextInput(text)
    .performImeAction()

Try this!!!

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.