1

Firstly, I've turned off all the animation settings:

  • Window animation scale
  • Transition animation scale
  • Animator duration scale

Recently I need to add Espresso test cases for an old Android project(5 years+), and I don't have enough time to digging around all the custom views.

After reading many other posts here, I know that custom views might trigger this one, Espresso: AppNotIdleException

I did try to read the threads info as Espresso test error: AppNotIdleException and espresso onView inconsistent performance, but it seems that's not easy to fetch info from it(146 threads in my case): enter image description here

I tried to search the android:repeatCount in the code base(via This SO answer), once again, not related. enter image description here

There're several QAs related to this issue, but it seems they're not applying to my specific case.

The layout file that I want to click is simple:

<RelativeLayout
    android:id="@+id/home_tab_discover"
    style="@style/home_tab_item">

    <SomeCustomImageView
        android:id="@+id/home_tab_icon_discover"
     ...

The espresso case:

@Test
fun test_shelf_enter() {
    Espresso.onView(ViewMatchers.withId(R.id.home_tab_icon_discover)).perform(ViewActions.click())
}

Then it launch the app, and I did see all the elements in the activity, but the Espresso waited infinitely.

enter image description here

pvd
  • 1,303
  • 2
  • 16
  • 31
  • Your Main Thread must be busy doing stuff. This usually happens with infinite animations or ProgressBars. You'll have to check what the custom view is doing and work around it. Maybe try to disable animations with one of the multiple methods available, like https://medium.com/@balachandarkm/disable-animations-while-running-android-ui-tests-2d1748280156 – Sloy May 28 '21 at 15:17
  • Thanks @Sloy , I had disabled the animations before testing. – pvd May 29 '21 at 03:40
  • 1
    Could you share the layout xml that cause AppNotIdleException? – Aaron May 30 '21 at 03:33
  • @Aaron Awesome thanks for your help. https://gist.github.com/impvd/fb5e27447bf0abfc94f211b2165fcc03 – pvd May 31 '21 at 12:13
  • 1
    What are the views in your ViewPager? AppNotIdleException means the main thread or the UI thread is busy, so I'm guessing there's either animating view or IdlingResource running in the background. – Aaron May 31 '21 at 12:31
  • Thanks for sharing, but I guess you'll have to get deeper into the code, ViewPager contains other views created by the adapter, try to look for suspicious views, such as ProgressBar, sometimes these views can cause AppNotIdleException even when you have turned off the animations from dev settings (vary on Android versions and devices). If that's the case, then try removing or set their visibility to GONE. – Aaron May 31 '21 at 13:03

1 Answers1

0

It totally seems something related with your production code. I would say you should check the app itself. Maybe debugging what happens there? What's happening in the Activity you are testing?

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
  • Thanks for your replying. I was wondering if there're any guide to debug this kind of bug? like, use some keyword to search the code base? Or use some tool within Android Studio to see why espresso stuck forever? – pvd May 29 '21 at 06:37
  • Nope... but you can just debug your app. Add a breakpoint to the Activity you are testing, and run the tests in debugging mode instead of just passing them. You know, tap the bug button instead of the regular play one on Android Studio :·) – Roc Boronat May 31 '21 at 05:06
  • 1
    After reading https://proandroiddev.com/progressbar-animations-with-espresso-57f826102187 , it sounds a lot like animations is always a nightmare for Espresso. I've disable the animations setting in mobile phone's setting, but it still stuck. Maybe I should use UIAutmator instead. – pvd May 31 '21 at 12:51
  • Did you find a workaround @pvd? Or just moved to UI Automator? – JCarlosR Sep 12 '22 at 21:16
  • @JCarlosR I'm using UI Automator for a while:) – pvd Dec 26 '22 at 03:48