androidandroid-espressoandroid-espresso-recorder

Espresso: Click action on button in ListView footer


ListView has footer like this (footer.xml):

<?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>

When recording the script (via the 'Record Espresso Test' in Android Studio) I received the following code to click the button 'Next':

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());
}

It works good but... when the test is runned on device with low resolution I get error:

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.

How to customize the test for lower resolutions?


Solution

  • The problem is whole footer isn't shown on the screen (just part if is shown). You can try to do swipeUp action before clicking on the button. Or, if swipe isn't helping, just check why you are not seeing it on smaller screens.