Тест Espresso Recorder выдает ошибку: зацикливание на 3600 итераций в течение 60 секунд - PullRequest
0 голосов
/ 13 июня 2018

Я пытаюсь сгенерировать юнит-тесты в своем приложении для Android.Я использовал инструмент Record Espresso.

Мое приложение запускается с SplashScreen, а затем запускает намерение MainActivity, где отображается главное меню.Основным действием является фрагмент с четырьмя вкладками.

Я попытался сгенерировать несколько отдельных тестов, используя элементы основного действия.Например: откройте навигационный ящик, выберите элемент в 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>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...