0

ListView a pied comme celui-ci (footer.xml):Espresso: Cliquez sur l'action sur le bouton en bas de page ListView

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <Button 
     android:id="@+id/btn_cancel" 
     style="@style/MyApp.Form.Component.Button" 
     android:text="@string/action_cancel"/> 

    <Button 
     android:id="@+id/btn_confirm" 
     style="@style/MyApp.Form.Component.Button" 
     android:text="@string/action_next"/> 
</RelativeLayout> 

Lors de l'enregistrement du script (via le 'Test enregistrement Espresso' dans Android Studio) J'ai reçu les éléments suivants Code de cliquer sur le bouton « Suivant »:

private void clickNext() { 
    ViewInteraction appCompatButton2 = onView(
      allOf(withId(R.id.btn_confirm), withText("Next"), 
        withParent(childAtPosition(
          withId(R.id.lv_products), 5)))); 
    appCompatButton2.perform(click()); 
} 

Il fonctionne bien, mais ... quand le test est lancée sur appareil avec une faible résolution, j'obtiens l'erreur:

android.support.test.espresso.PerformException: Error performing 'single click' on view '(with id: com.comarch.msc.emulator:id/btn_confirm and with text: is "Next" and has parent matching: Child at position 5 in parent with id: com.comarch.msc.emulator:id/lv_products)'. (...) Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view's area is displayed to the user.

Comment personnaliser le test pour les résolutions inférieures?

+0

Possible copie de [Cliquez sur imageButton pas entièrement visible avec Espresso] (http://stackoverflow.com/questions/28834579/click-on-not-fully-visible-imagebutton-with-espresso) –

Répondre

1

Le problème est que le pied de page entier n'est pas affiché à l'écran (une partie seulement est montrée). Vous pouvez essayer de faire l'action swipeUp avant de cliquer sur le bouton. Ou, si le balayage ne vous aide pas, vérifiez simplement pourquoi vous ne le voyez pas sur des écrans plus petits.

+0

swipeUp fonctionne! Merci! –