title: Android Espresso doesn't wait for fragments to load
body: <p>I'm just getting started with Espresso for testing Android apps, but I'm having some trouble. I have an Activity with a button that replaces a fragment in the usual way:</p>
  
  <pre><code>public void onClick(View v) {
      final FragmentTransaction t = getFragmentManager().beginTransaction();
      t.setCustomAnimations(R.animator.fragment_slide_in_up, 0);
      t.replace(R.id.fragment_container,
          LogInFragment.newInstance(), LogInFragment.TAG)
          .addToBackStack(LogInFragment.TAG);
      t.commit();
  }
  </code></pre>
  
  <p>In my test, I click the button that sends in the new fragment, and then just check that the new fragment is visible.</p>
  
  <pre><code>onView(withId(R.id.login_btn))
      .perform(click());
  Thread.sleep(500);
  onView(withId(R.id.email_input))
      .check(matches(isDisplayed()));
  </code></pre>
  
  <p>If I remove the <code>Thread.sleep()</code> from the test, the test fails, even if I remove the <code>setCustomAnimations()</code> from the Activity code.</p>
  
  <p>All animations are turned off on my phone, as per the instructions.  My understanding is that Espresso knows about the UI thread status and will wait until everything is ready.  But if I do a <code>onView(withId(R.id.widgetOnNewFragment))</code> it blows up every time.  I need to add a <code>Thread.sleep(500)</code> every time I show a new fragment.</p>
  
  <p>Am I missing something?  I think I should not have to add dozens of Thread.sleep() to my test code.</p>