简体   繁体   English

浓咖啡:在ListView页脚中单击按钮上的操作

[英]Espresso: Click action on button in ListView footer

ListView has footer like this (footer.xml): ListView具有这样的页脚(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': 记录脚本时(通过Android Studio中的“记录Espresso测试”),我收到以下代码,以单击“下一步”按钮:

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)'. android.support.test.espresso.PerformException:在视图'(ID为com.comarch.msc.emulator:id / btn_confirm且文本为“ Next”且父项匹配:在位置为子级)上执行“单击”时出错ID为com.comarch.msc.emulator:id / lv_products)的父级中的5个。 (...) 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. (...)原因:java.lang.RuntimeException:由于目标视图与以下一个或多个约束不匹配,因此不会执行操作:向用户显示视图面积的至少90%。

How to customize the test for lower resolutions? 如何自定义较低分辨率的测试?

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. 您可以在点击按钮之前尝试执行swipeUp操作。 Or, if swipe isn't helping, just check why you are not seeing it on smaller screens. 或者,如果滑动操作无济于事,只需检查一下为什么在较小的屏幕上看不到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM