2017-01-10 2 views
0

Essayer de tester ma connexion avec un expresso. Si je clique juste sur mon champ, alors tout va bien.TypeText ne fonctionne pas

ViewInteraction linearLayout = onView(
      allOf(childAtPosition(
        allOf(withId(R.id.nameEditText), 
          childAtPosition(
            withId(R.id.inputLayout), 
            0)), 
        0), 
        isDisplayed())); 
    linearLayout.check(matches(isDisplayed())) 
      .perform(click()); 

Mais si je dois mettre un texte dans ce domaine, j'ai quelques problèmes:

ViewInteraction linearLayout = onView(
      allOf(childAtPosition(
        allOf(withId(R.id.nameEditText), 
          childAtPosition(
            withId(R.id.inputLayout), 
            0)), 
        0), 
        isDisplayed())); 
    linearLayout.check(matches(isDisplayed())) 
      .perform(typeText("SomeName")); 

Et obtenez l'erreur suivante:

android.support.test.espresso.PerformException: Error performing 'type text(SomeName)' on view '(Child at position 0 in parent (with id: com.fentury.android:id/nameEditText and Child at position 0 in parent with id: com.fentury.android:id/inputLayout)

OU

Si j'essaie de faire de cette façon:

ViewInteraction appCompatEditText = onView(
      allOf(withId(R.id.nameEditText), 
        withParent(withId(R.id.inputLayout)), isDisplayed())); 
    appCompatEditText.check(matches(isDisplayed())) 
      .perform(click()).perform(typeText("Dog")); 

J'AGAiT la même erreur:

android.support.test.espresso.PerformException: Error performing 'type text(Dog)' on view '(with id: com.fentury.android:id/nameEditText and has parent matching: with id: com.fentury.android:id/inputLayout and is displayed on the screen to the user)'

Comment puis-je résoudre cette erreur?

+0

Pourriez-vous fournir votre mise en page? Si vous l'avez nommé correctement, linearLayout ne peut pas saisir de texte. – quanlt

Répondre

0

Utilisez-vous TextInputLayout?

Ci-dessous travaillé pour moi avec TextInputLayout.

onView(
      allOf(
        isDescendantOfA(withId(R.id.nameEditText)), 
        isAssignableFrom(EditText.class))) 
      .perform(typeText("some text"));