Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

espresso onView inconsistent performance

I am using Junit4 and Espresso for my tests. I am facing a weird issue with espresso tests - when I call onView sometimes everything is executed like it is supposed to, but sometimes my test freezes and after 60 seconds I get something like this "android.support.test.espresso.AppNotIdleException: Looped for 63 iterations over 60 SECONDS. The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED" For example :

    onView(withId(R.id.zone_button_continue)).perform(click());
    onView(withId(R.id.loginButton)).check(matches(isDisplayed()));
    onView(withId(R.id.number)).check(matches(isDisplayed()));
    onView(withId(R.id.password)).check(matches(isDisplayed()));
    onView(withId(R.id.number)).perform(typeText(phoneNumber));
    onView(withId(R.id.password)).perform(typeText(password));
    onView(withId(R.id.loginButton)).perform(click());

everything gets executed correctly, except the last line - for some reason it can't find that loginButton, but it is there 100% percent. I can do

activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            activity.findViewById(R.id.loginButton).performClick();
             }
    });

and that works. I have similar problems throughout most of my activities - sometimes onView is working sometimes not.

What could cause such an inconsistency? I have been fighting with this issue for a while, and it makes my testing very frustrating and difficult. My conclusions this far is that something is wrong with my gradle dependencies or there is some kind of bug in my application that prevents espresso to work properly. But it is strange that in the example above everything with onView is working except last line and everything is happening in one activity and that makes me doubt that the bug is within my application. Here are my gradle dependencies:

compile files('src/main/libs/guice-3.0-no_aop.jar')
compile files('src/main/libs/javax.inject-1.jar')
compile files('src/main/libs/roboguice-2.0.jar')
compile files('src/main/libs/junit-4.11.jar')
compile files('src/main/libs/hamcrest-core-1.3.jar')
compile files('src/main/libs/GeoLib.jar')
compile files('src/main/libs/GeoPolygons.jar')
compile files('src/main/libs/universal-image-loader-1.9.4.jar')
compile files('src/main/libs/javax.annotation-3.2-b06-sources.jar')
compile ('uk.co.chrisjenx:calligraphy:2.1.0'){
    exclude group:'com.android.support'
}
compile 'com.squareup:otto:1.3.5'
compile ('com.google.android.gms:play-services:6.5.87'){
    exclude group:'com.android.support'
}
compile 'com.android.support:support-annotations:22.2.1'
compile ('com.android.support:appcompat-v7:22.2.0'){
    exclude group:'com.android.support'
}
compile ('com.android.support:support-v4:22.2.0'){
    exclude group:'com.android.support', module:'support-annotations'
}
compile ('com.android.support:palette-v7:22.2.0'){
    exclude group:'com.android.support'
}
compile 'com.google.code.findbugs:jsr305:2.0.1'

compile 'com.nineoldandroids:library:2.4.0'
compile 'pl.charmas.android:android-reactive-location:0.4@aar'
compile 'io.reactivex:rxjava:1.0.3'
compile files('src/main/libs/FlurryAnalytics-6.1.0.jar')
compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
//    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('com.android.support.test:runner:0.4.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to use JUnit 4 rules
androidTestCompile('com.android.support.test:rules:0.4.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to build and run Espresso tests
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}

androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.1') {
    // PackagingOptions modified to make this work
    exclude group: 'com.android.support', module: 'support-annotations'
}
testCompile 'junit:junit:4.11'
testCompile ('org.mockito:mockito-core:1.9.5'){
    exclude group: 'org.hamcrest'
}
compile 'org.mod4j.org.apache.commons:lang:2.1.0'

Please help me with this problem, I am completely out of ideas and stuck with it.

like image 359
Niks Avatar asked Feb 17 '16 15:02

Niks


2 Answers

The easiest way to see why you get an AppNotIdleExceptionwith the message "The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED", is to:

  • Run the tests in debug mode in Android Studio
  • Wait until the tests hang
  • Before the (default) 60 seconds have passed, pause the tests
  • Look in the "Threads" list and see your threads named "AsyncTask #1" and so on. Expand the one being in state RUNNING. There you see what part of the code is keeping the app busy

This was the result for my case, so I had to disable the Facebook SDK for my tests to make them stable again:

Threads view while debugging

like image 129
Eirik W Avatar answered Nov 20 '22 21:11

Eirik W


Had the same problem, also a bug with facebook libraries. Switched to a different emulated device and everything works normally!

like image 24
Petermonteer Avatar answered Nov 20 '22 21:11

Petermonteer