Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
Espresso error typing some text into TextInputLayout

I want to test my login UI which contains some TextInputLayout fields , i have set up some code to run but it crashes and throws an error , can anyone please with this issue , i appreciate in advance

  • I want to simply type some text into TextInputLayout
    @Test
    fun testCaseSimulateLoginOnButtonClick(){
        onView(withId(R.id.loginEmail)).perform(typeText("xxxxxxxx@gmail.com"))
        onView(withId(R.id.loginPassword)).perform(typeText("123456"))
        onView(withId(R.id.loginBtn)).perform(click())
        onView(withId(R.id.drawer)).check(matches(isDisplayed()))
    }
  • This is the error i get
Error performing 'type text(xxxxxxxx@gmail.com)' on view 'view.getId() is <2131362123/com.example.app:id/loginEmail>'.
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can't type text in the TextInputLayout view, that is just a container. The TextInputLayout has a FrameLayout as a direct child, and in that FrameLayout the first child view is the EditText (which you can type into)

You can get the EditText in Espresso with some extra matchers (find a view that is a descendant of the base R.id.text_layout layout and has a class name that ends with EditText).

onView(
    allOf(
        isDescendantOfA(withId(R.id.text_layout)),
        withClassName(endsWith("EditText"))
    )
).perform(
    typeText("Hello world")
)

If you have to do this in a lot of places, you can write a helper function

fun isEditTextInLayout(parentViewId: Int): Matcher<View> {
    return allOf(
        isDescendantOfA(withId(parentViewId)),
        withClassName(endsWith("EditText"))
    )
}

and use it as

onView(isEditTextInLayout(R.id.text_layout)).perform(typeText("Hello world"))

for an XML that looks like

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/text_layout"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Type words here"
    android:layout_margin="16dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" >

    <androidx.appcompat.widget.AppCompatEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

Some of the required imports for this to work are

import androidx.test.espresso.matcher.ViewMatchers.*
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.endsWith

Of course, you could also just add an android:id for the EditText and get it that way too...

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda