Espresso - typeText not working

Viewed 22038

I'm trying to type some text inside an EditText:


    public void testSearch() {
          onView(withId(R.id.titleInput)).perform(typeText("Engineer"));
          onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
    }

I see the EditText is getting focus, but nothing happens. No text is typed.
I tried this on a phone and an emulator - same result.

10 Answers

Same issue resolved with the following:

editText.perform(scrollTo(), click(), clearText(), typeText(myInput), closeSoftKeyboard())

Interestingly, I only ever had a problem when my machine was working hard.

I fixed this issue by setting layout_height="wrap_content" on the View I wanted to click(). Maybe it can help someone here.

for me I was annotated my test method with @UiThreadTest. I removed that and it solved.

Adding closeSoftKeyboard() after typeText() worked for me.

CODE:

onView(withId(R.id.editTextUserInput))
            .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());

This is how it is documented in the Android docs.

Related