Ошибки при запуске Теста на Espresso
Моя проблема заключается в том, что тесты с помощью Espresso постоянно падают. В начале причина была понятна, это асинхронная операция но добавив idling resource ничего не изменилось.
Ниже представляю код теста
@LargeTest
@RunWith(AndroidJUnit4.class)
public class AppActivityTest {
@Rule
public ActivityScenarioRule<AppActivity> mActivityScenarioRule =
new ActivityScenarioRule<>(AppActivity.class);
@Before // Выполняется перед тестами
public void registerIdlingResources() { //Подключаемся к “счетчику”
IdlingRegistry.getInstance().register(EspressoIdlingResources.idlingResource);
}
@After // Выполняется после тестов
public void unregisterIdlingResources() { //Отключаемся от “счетчика”
IdlingRegistry.getInstance().unregister(EspressoIdlingResources.idlingResource);
}
@Test
public void appActivityTest() {
ViewInteraction textInputEditText = onView(
allOf(childAtPosition(
childAtPosition(
allOf(withId(R.id.login_text_input_layout),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.RelativeLayout")),
1),
0)),
0),
0),
isDisplayed()));
textInputEditText.perform(replaceText("login2"), closeSoftKeyboard());
ViewInteraction textInputEditText2 = onView(
allOf(childAtPosition(
childAtPosition(
allOf(withId(R.id.password_text_input_layout),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.RelativeLayout")),
1),
1)),
0),
0),
isDisplayed()));
textInputEditText2.perform(replaceText("password2"), closeSoftKeyboard());
ViewInteraction materialButton = onView(
allOf(withId(R.id.enter_button), withText("Sign in"), withContentDescription("Save"),
childAtPosition(
childAtPosition(
childAtPosition(
childAtPosition(
withId(R.id.nav_host_fragment),
0),
2),
1),
2),
isDisplayed()));
materialButton.perform(click());
ViewInteraction textView = onView(
allOf(withText("News"),
withParent(withParent(allOf(withId(R.id.container_list_news_include_on_fragment_main),
withParent(withParent(IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class)))))),
isDisplayed()));
textView.check(matches(withText("News")));
}
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));
}
};
}
}
А тут файл idlingResource
public class EspressoIdlingResources {
private static final String RESOURCE = "GLOBAL";//Tag
public static CountingIdlingResource idlingResource = new CountingIdlingResource(RESOURCE);
public static void increment() {
idlingResource.increment();
}
public static void decrement() {
if(!idlingResource.isIdleNow()) {
idlingResource.decrement();
}
}
}
А здесь ошибка
failed: appActivityTest(ru.iteco.fmhandroid.ui.AppActivityTest)
----- begin exception -----
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (Child at position 0 in parent Child at position 0 in parent (view.getId() is <2131231037/ru.iteco.fmhandroid:id/login_text_input_layout> and Child at position 0 in parent Child at position 1 in parent view.getClass().getName() matches: is "android.widget.RelativeLayout") and (view has effective visibility <VISIBLE> and view.getGlobalVisibleRect() to return non-empty rectangle))
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1344, height=2992, 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=false, is-selected=false, layout-params={(0,0)(fillxfill) ty=BASE_APPLICATION wanim=0x10302fe
fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
pfl=NO_MOVE_ANIMATION FORCE_DRAW_STATUS_BAR_BACKGROUND FIT_INSETS_CONTROLLED
bhv=DEFAULT
fitSides=}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1344, height=2848, 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=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@YYYYYY, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+-->ViewStub{id=16908720, res-name=action_mode_bar_stub, 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, layout-params=android.widget.LinearLayout$LayoutParams@YYYYYY, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+-->FrameLayout{id=-1, visibility=VISIBLE, width=1344, height=2848, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@YYYYYY, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+--->FitWindowsLinearLayout{id=2131230784, res-name=action_bar_root, visibility=VISIBLE, width=1344, height=2848, 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=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@YYYYYY, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+---->ViewStubCompat{id=2131230801, res-name=action_mode_bar_stub, 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, layout-params=android.widget.LinearLayout$LayoutParams@YYYYYY, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+---->ContentFrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=1344, height=2848, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@YYYYYY, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
at androidx.test.espresso.base.ViewHierarchyExceptionHandler.handleSafely(ViewHierarchyExceptionHandler.java:38)
at androidx.test.espresso.base.DefaultFailureHandler$TypedFailureHandler.handle(DefaultFailureHandler.java:158)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:120)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:385)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:212)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:140)
at ru.iteco.fmhandroid.ui.AppActivityTest.appActivityTest(AppActivityTest.java:71)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:54)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:162)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:68)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:463)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2248)
Прошу помогите решить проблему и направить на путь истинный, я только учусь этому но даже преподаватель отказывается что то объяснять.....
В самом начале и гугл и чат GPT и пытался что то понять в документации.