lundi 7 décembre 2015

Android: how to use Espresso to test that a buttons bgcolor has changed when it's being held down?

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 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?

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<View> withTextColor(final int color) {
        Checks.checkNotNull(color);
        return new BoundedMatcher<View, TextView>(TextView.class) {
            @Override
            public boolean matchesSafely(TextView warning) {
                return color == warning.getCurrentTextColor();
            }
            @Override
            public void describeTo(Description description) {
                description.appendText("with text color: ");
            }
        };
    }

The error that I'm getting is:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with string from resource id: <someid>

Aucun commentaire:

Enregistrer un commentaire