title: Android: how to use Espresso to test that a buttons bgcolor has changed when it's being held down?
body: <p>I want to use Espresso to test that a button that has a color selector as it's background is really changing color properly when the user presses on it. However, when I try to do this with espresso the actual click is being registered so fast that the button performs it's behavior (starting a progressbar) and the test fails with "view not found". How can I test that the background color changed when the user presses on it without/before performing the button logic? Essentially what I'm looking for here is a way to simulate OnTouchListener's Action_Down.</p>
  
  <pre><code>Espresso.onView(ViewMatchers.withId(R.id.somebutton)).perform(ViewActions.click());
  
  Espresso.onView(ViewMatchers.withText(R.string.somebuttonText)).check(ViewAssertions.matches(withTextColor(Color.BLACK)));
  
  
     public static Matcher&lt;View&gt; withTextColor(final int color) {
          Checks.checkNotNull(color);
          return new BoundedMatcher&lt;View, TextView&gt;(TextView.class) {
              @Override
              public boolean matchesSafely(TextView warning) {
                  return color == warning.getCurrentTextColor();
              }
              @Override
              public void describeTo(Description description) {
                  description.appendText("with text color: ");
              }
          };
      }
  </code></pre>
  
  <p>The error that I'm getting is:</p>
  
  <pre><code>android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with string from resource id: &lt;someid&gt;
  </code></pre>
  
  <p>I also tried to do it this way and it fails with the same error:</p>
  
  <pre><code>    ViewInteraction somebuttoninteraction = Espresso.onView(ViewMatchers.withText(R.string.somebuttontext));
      somebuttoninteraction.perform(ViewActions.click()).check(ViewAssertions.matches(withTextColor(Color.BLACK)));
  </code></pre>
  
  <p>I also tried like this (longclick instead of click) but still the same:</p>
  
  <pre><code>somebuttoninteraction.perform(ViewActions.longClick()).check(ViewAssertions.matches(withTextColor(Color.BLACK)));
  </code></pre>