Prüfung background-color espresso-Android

Ist es möglich zu überprüfen, ob die hintergrund-Farbe entspricht einer bestimmten Farbe mit espresso?

Machte ich eine custom matcher, ähnlich zu dem, was @Irfan vorgeschlagen, danke!

public static Matcher<Object> backgroundShouldHaveColor(int expectedColor) {
    return buttondShouldHaveBackgroundColor(equalTo(expectedColor));
}
private static Matcher<Object> buttonShouldHaveBackgroundColor(final Matcher<Integer> expectedObject) {
    final int[] color = new int[1];
    return new BoundedMatcher<Object, Button>( Button.class) {
        @Override
        public boolean matchesSafely(final Button actualObject) {

            color[0] =((ColorDrawable) actualObject.getBackground()).getColor();


            if( expectedObject.matches(color[0])) {
                return true;
            } else {
                return false;
            }
        }
        @Override
        public void describeTo(final Description description) {
            //Should be improved!
            description.appendText("Color did not match "+color[0]);
        }
    };
}
InformationsquelleAutor HowieH | 2015-02-26
Schreibe einen Kommentar