android - Espresso Recorder Test 向我抛出错误: Looped for 3600 iterations over 60 SECONDS
问题描述
我正在尝试在我的 Android 应用程序中生成单元测试。我使用了 Record Espresso 工具。
我的应用程序以 SplashScreen 开始,然后向显示主菜单的 MainActivity 启动意图。主要活动是一个带有四个选项卡的片段。
我尝试使用主要活动的元素生成几个单独的测试。Fe .: 打开导航抽屉,在 listView 中选择一个项目,按下 FAB 按钮......总是得到同样的错误:
android.support.test.espresso.AppNotIdleException: Looped for 3600 iterations over 60 SECONDS.
这是使用 Espresso Recorder 生成的测试代码之一。选择匹配列表中的第一项,然后按返回按钮。
public class SplashScreenTest {
@Rule
public ActivityTestRule<SplashScreen> mActivityTestRule = new ActivityTestRule<>(SplashScreen.class);
@Test
public void splashScreenTest() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(30380);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction linearLayout = onView(
allOf(childAtPosition(
allOf(withId(R.id.listaPartidos),
withParent(allOf(withClassName(is("android.widget.LinearLayout")),
withParent(allOf(withClassName(is("android.widget.RelativeLayout")),
withParent(withId(R.id.viewpager))))))),
0),
isDisplayed()));
linearLayout.perform(click());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(30892);
} catch (InterruptedException e) {
e.printStackTrace();
}
pressBack();
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}}
有人可以告诉我在哪里可以找到解决方案吗?
SplashScreen 仅启动 MainActivity。这执行了访问数据和信息可视化的逻辑。
编辑:主要活动的XML文件是三个:第一,activity_inicio.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_inicio"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemBackground="@android:color/transparent"
app:headerLayout="@layout/menu_encabezado"
app:menu="@menu/activity_inicio_drawer" />
然后,app_bar_inicio.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
tools:context="ccv.dam.isi.frsf.utn.edu.ar.tpdam2016.Actividades.inicio.Inicio">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<Spinner
android:id="@+id/spinnerCampeonatoInicio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:gravity="center_vertical"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_inicio" />
最后是 contenido_inicio,其中声明了 tabHost。四个选项卡以编程方式合并
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="ccv.dam.isi.frsf.utn.edu.ar.tpdam2016.Actividades.inicio.Inicio"
tools:showIn="@layout/app_bar_inicio">
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal"
android:background="?attr/colorPrimary"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:background="@color/colorBlanco"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</TabHost>
解决方案
推荐阅读
- docker - Windows Docker NAT 似乎完全崩溃了
- google-colaboratory - 使 colab 使用最新安装的库
- internet-explorer - Internet Explorer 中的多个 Select2 标记问题
- javascript - 访问用户集合中的数组。[Meteor + React Native]
- unity3d - Unity3D - 为什么以简单复制的方式重构我的脚本不起作用?
- javascript - 将 Array.push 作为参数传递会在 JavaScript 中引发异常
- sql - RODBC:围绕 SQL Server APPENDS 的日期时间值引用
- git - 在 VSCode 中跟踪子文件夹中的 git 更改
- node.js - 我正在尝试在 node.js 项目中的模块之间传递数据,但我遗漏了一些东西
- android - 使用 ContactsContract,查询匹配的姓名或电子邮件