【发布时间】:2016-12-03 19:13:37
【问题描述】:
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>
在录制脚本时(通过 Android Studio 中的“Record Espresso Test”),我收到以下代码以单击“下一步”按钮:
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());
}
效果很好,但是...在低分辨率设备上运行测试时出现错误:
android.support.test.espresso.PerformException:执行错误 '单击'视图'(带有ID: com.comarch.msc.emulator:id/btn_confirm 和文本:是“下一步”和 有父匹配:在父级中位置 5 的子级,ID: com.comarch.msc.emulator:id/lv_products)'。 (...) 原因: java.lang.RuntimeException:将不会执行操作,因为 目标视图与以下一项或多项约束不匹配: 至少 90% 的视图区域会显示给用户。
如何自定义低分辨率测试?
【问题讨论】:
标签: android android-espresso android-espresso-recorder