Testing background color espresso Android
In my tests I have the following matcher for testing EditText
color:
public static Matcher<View> withTextColor(final int color) {
Checks.checkNotNull(color);
return new BoundedMatcher<View, EditText>(EditText.class) {
@Override
public boolean matchesSafely(EditText warning) {
return color == warning.getCurrentTextColor();
}
@Override
public void describeTo(Description description) {
description.appendText("with text color: ");
}
};
}
And usage is :
onView(withId(R.id.password_edittext)).check(matches(withTextColor(Color.RED)));
I am not sure about that but we can retrieve the color of some of elements like button and text views `
Button button = (Button) findViewById(R.id.my_button);
Drawable buttonBackground = button.getBackground();
and you can try like this
ColorDrawable b_color = (ColorDrawable) button.getBackground();
and then
int color = b_color.getColor();
if (color == R.color.green) {
log("color is green");
}
Hope this will get you started.