【发布时间】:2014-07-29 13:22:25
【问题描述】:
如何在 Espresso 测试中打开标签?我试图做Espresso.onView(ViewMatchers.withId(R.id.practice_results_tab)).perform(ViewActions.click());,但这不起作用。在该代码中,我打开了此选项卡的布局。
有XML文件:
<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/practice_tabHost">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/practice_settings_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/practice_results_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
我应该使用什么 ID 来打开标签页?
logcat 中的错误:
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.
Target view: "LinearLayout{id=2131296384, res-name=practice_results_tab, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}"
【问题讨论】:
-
该异常的完整堆栈跟踪是什么?对于 PerformExceptions,“Caused by”部分是最重要的。
-
@haffax 添加完整的堆栈跟踪。
-
该错误表明您的目标视图是线性布局。我将首先在 xml 中仔细检查您的 id。你的标签上有文字吗?你能用“onView(withText('string here'))”来引用你的观点吗?
-
@Maxwell 添加 xml 文件。我不明白我应该如何打开标签?
标签: android android-tabs android-espresso