title: Android Espresso 2 gets stuck in dialog
body: <p>I want to test a login activity with Espresso 2.2.1.</p>
  
  <p>When the user types in a wrong username / password combination and clicks the login-button, a progress dialog shall appear and a http request is started. After that, when the server answers that the password was wrong, an error dialog shall appear.</p>
  
  <p>This is my test code:</p>
  
  <pre><code>@Test
   public void testLoginInvalid() {
      ViewInteraction emailViewInteraction = Espresso.onView(ViewMatchers.withId(R.id.email));
      ViewInteraction passwordViewInteraction = Espresso.onView(ViewMatchers.withId(R.id.password));
      ViewInteraction loginButtonViewInteraction = Espresso.onView(ViewMatchers.withId(R.id.login_button));
  
      emailViewInteraction.perform(ViewActions.typeText("example_username"));
      passwordViewInteraction.perform(ViewActions.typeText("invalid_password"));
      loginButtonViewInteraction.perform(ViewActions.click());
  
      Espresso.onView(ViewMatchers.withText(R.string.dialog_exception_title)).inRoot(RootMatchers.isDialog()).check(ViewAssertions.matches(ViewMatchers.isDisplayed())); 
      Espresso.onView(ViewMatchers.withId(android.R.id.button1)).perform(ViewActions.click());
  
      Intents.assertNoUnverifiedIntents();
  }
  </code></pre>
  
  <p>It works fine until</p>
  
  <pre><code>loginButtonViewInteraction.perform(ViewActions.click());
  </code></pre>
  
  <p>The progress dialog shows up, then the exception dialog. But then it gets stuck. The next line </p>
  
  <pre><code>Espresso.onView(ViewMatchers.withText(R.string.dialog_exception_title)).inRoot(RootMatchers.isDialog()).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
  </code></pre>
  
  <p>is not called. I have to manually click the ok-button in the exception-dialog, only then the test continues. Of course it fails then, because the dialog is dismissed after manually clicking ok.</p>
  
  <p>When i do not click manually, the test times out after 60 seconds:</p>
  
  <pre><code>    android.support.test.espresso.PerformException: Error performing 'single click' on view 'with id: com.uclapp:id/login_button'.
  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:184)
  at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
  at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
  at com.uclapp.tests.integration.ui.LoginActivityTest.testLoginInvalid(LoginActivityTest.java:113)
  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:257)
  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:54)
  at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:240)
  at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1837)
  Caused by: android.support.test.espresso.AppNotIdleException: Looped for 3558 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:477)
  at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:408)
  at android.support.test.espresso.base.UiControllerImpl.injectMotionEvent(UiControllerImpl.java:226)
  at android.support.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:138)
  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.java:144)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:211)
  at android.app.ActivityThread.main(ActivityThread.java:5317)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
  </code></pre>
  
  <p>I debugged it further and the problem seems to be, that on UIControllerImpl line 460:</p>
  
  <pre><code>QueueState queueState = queueInterrogator.determineQueueState();
  </code></pre>
  
  <p>The queueState is always BARRIER.</p>
  
  <p>How can i solve this?</p>