title: Espresso does not wait until dialog is shown and fail
body: <p>I'm working with some simple tests with Espresso. One of them is about click on view and check if a Dialog is showed.</p>
  
  <p>My problem is that sometimes works, and sometimes not. It only work always if I put a <em>sleep</em> before check the dialog. Any solution without ussing <em>sleep</em>?</p>
  
  <p>Here is my code (so simple):</p>
  
  <pre><code>onView(withId(R.id.forgot_password)).perform(click());
  // only works if use Thread.sleep(ms) here
  onView(withText(R.string.reset_password)).check(matches(isDisplayed()));
  </code></pre>
  
  <p>Edit:</p>
  
  <p>I'm showing dialog with static helpers, but the simplification is this. And I'm not performing any background task in the middle.</p>
  
  <p>final TextInputDialog textInputDialog = new </p>
  
  <pre><code>TextInputDialog.Builder(context)
                  .setTitle(titleId)
                  .setInputType(inputType)
                  .setHint(hintId)
                  .setPreFilledText(preFilledText)
                  .setNegativeButton(R.string.cancel, null)
                  .setPositiveButton(positiveButtonId, onTextSubmittedListener)
                  .create();
  textInputDialog.show(textInputDialog);
  </code></pre>
  
  <p>Thank you!</p>