Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso test fails after successful click and blocking for 60 seconds

Tags:

I have tried using Espresso testing framework and wrote a simple test.

Nothing fancy there, just this code:

onView(withId(R.id.login_button_stub)).perform(click());

Test runs fine on a Nexus 5 device and Genymotion with Android 5.0, but fails on Android Emulator 4.x, 5.0, Genymotion 2.3, 4.x and LG G2 with Android 4.x.

On all these devices/emulators/simulators, the button is clicked and its action executed (going to another screen in my case). The problem is it blocks in perform on some devices. This ends with a nice exception after 60 seconds:

android.support.test.espresso.PerformException: Error performing 'single click' on view 'with id: com.vielengames.mock:id/login_button_stub'.
    ...
    Caused by: android.support.test.espresso.AppNotIdleException: Looped for 3544 iterations over 60 SECONDS. The following Idle Conditions failed .
    ...

Note that there is no info about what conditions failed. Looking at Espresso source code, there should be a comma-separated list of issues.

Here is the full code: TestCase.java.

and full stacktrace:

I/TestRunner﹕ android.support.test.espresso.PerformException: Error performing 'single click' on view 'with id: com.vielengames.mock:id/login_button_stub'.
        at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
        at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:70)
        at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:53)
        at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:185)
        at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
        at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
        at com.vielengames.ui.NotLoggedOnTestCase.testLoggedOnAfterLoginClick(NotLoggedOnTestCase.java:19)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
        at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
        at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at junit.framework.TestResult$1.protect(TestResult.java:115)
        at junit.framework.TestResult.runProtected(TestResult.java:133)
        at android.support.test.internal.runner.junit3.DelegatingTestResult.runProtected(DelegatingTestResult.java:90)
        at junit.framework.TestResult.run(TestResult.java:118)
        at android.support.test.internal.runner.junit3.AndroidTestResult.run(AndroidTestResult.java:49)
        at junit.framework.TestCase.run(TestCase.java:124)
        at android.support.test.internal.runner.junit3.NonLeakyTestSuite$NonLeakyTest.run(NonLeakyTestSuite.java:63)
        at junit.framework.TestSuite.runTest(TestSuite.java:243)
        at junit.framework.TestSuite.run(TestSuite.java:238)
        at android.support.test.internal.runner.junit3.DelegatingTestSuite.run(DelegatingTestSuite.java:103)
        at android.support.test.internal.runner.junit3.AndroidTestSuite.run(AndroidTestSuite.java:63)
        at android.support.test.internal.runner.junit3.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
        at org.junit.runners.Suite.runChild(Suite.java:128)
        at org.junit.runners.Suite.runChild(Suite.java:24)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
        at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:270)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
 Caused by: android.support.test.espresso.AppNotIdleException: Looped for 3544 iterations over 60 SECONDS. The following Idle Conditions failed .
        at android.support.test.espresso.IdlingPolicy.handleTimeout(IdlingPolicy.java:61)
        at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:471)
        at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:402)
        at android.support.test.espresso.base.UiControllerImpl.injectMotionEvent(UiControllerImpl.java:226)
        at android.support.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:135)
        at android.support.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:118)
        at android.support.test.espresso.action.Tap.sendSingleTap(Tap.java:135)
        at android.support.test.espresso.action.Tap.access$100(Tap.java:35)
        at android.support.test.espresso.action.Tap$1.sendTap(Tap.java:40)
        at android.support.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:98)
        at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction
like image 452
MaciejGórski Avatar asked Jan 21 '15 18:01

MaciejGórski


People also ask

Does espresso support test recording?

The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app.

How do you check espresso visibility?

One simple way to check for a View or its subclass like a Button is to use method getVisibility from View class. I must caution that visibility attribute is not clearly defined in the GUI world. A view may be considered visible but may be overlapped with another view, for one example, making it hidden.

How do you test espresso intent?

Validate intentsUsing the intended() method, which is similar to Mockito. verify() , you can assert that a given intent has been seen. However, Espresso-Intents doesn't stub out responses to intents unless you explicitly configure it to do so. // User action that results in an external "phone" activity being launched.


1 Answers

It was a bug in my app code, where SwipeRefreshLayout animated itself indefinitely. Due to a bug in this component, the refresh state was not even showing.

like image 161
MaciejGórski Avatar answered Dec 03 '22 03:12

MaciejGórski