Kavitha
Kavitha

Reputation: 1

appNotIdleException occurs

I am a beginner to Android espresso testing. I am trying to click one textview. if the textview does not have any value, then it is working after clicking.

But when the textview get value by doing some background process, that time it is not working correctly. in stead it is throwing an exception of AppNotIdleException. I have searched in Stack Overflow to resolve the issue. But I did not get any idea on resolving this issue.

My code is:

    @Test
    @MediumTest
    public void Test1_Spo2() throws InterruptedException 
    {

    PatientToMainActivity();

    Thread.sleep(1000);
    onView(withId(R.id.viewPager)).check(matches(withEffectiveVisibility(
    ViewMatchers.Visibility.VISIBLE)));

    onView(allOf(withId(R.id.txtSPO2),withText("SpO2")))
    .check(matches(isCompletelyDisplayed()));

   Thread.sleep(5000);
    //

   //onView(withId(R.id.imgSPO2))
   .check(matches(withDrawable(R.drawable.o2)));
    onView(withId(R.id.txtSPO2Value)).perform(click());

    Thread.sleep(1000);

    intended(hasComponent(new ComponentName(getTargetContext(),ChartActivity.class)));


}

after clicking that txtSpo2Value, it is showing the below exception.

android.support.test.espresso.AppNotIdleException: Looped for 8778   iterations over 60 SECONDS. The following Idle Conditions failed .
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:580)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError   (DefaultFailureHandler.java:92)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at anidra.com.berryapp.MainActivityLiveFragmentTest.Test1_Spo2(MainActivityLiveFragmentTest.java:99)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1851)

Upvotes: 0

Views: 939

Answers (1)

Anna
Anna

Reputation: 759

As far as I know there can be some reasons of this exception:

  1. there is dead lock of idling resources that you registered for your test class. You can check what you did for the test class.
  2. Are you sure nothing is holding the main/ui thread? go to Developer Settings of you device and enable "show screen/surface updates" then run the test and observe the device under test for any UI updates... if the screen is constantly flashing then something is constantly updating the UI thread, thus the app is never idle. This can be application problem, not the test itself.

I hope it can help you somehow...

Upvotes: 3

Related Questions