Testing background color espresso Android

前端 未结 7 921
灰色年华
灰色年华 2020-12-11 14:50

Is it possible to check if the background color matches a given color with espresso?

Update:

I made a custom matcher, similar to what @Irfa

相关标签:
7条回答
  • 2020-12-11 15:45

    Here is what i use in my tests

    public static Matcher<View> withTextColor(final int color) {
        Checks.checkNotNull(color);
            return new BoundedMatcher<View, TextView>(TextView.class) {
                @Override
                public boolean matchesSafely(TextView textView) {
                    return ContextCompat.getColor(getTargetContext(),color)==textView.getCurrentTextColor();
                }
                @Override
                public void describeTo(Description description) {
                    description.appendText("with text color: ");
                }
            };
    }
    

    and call it as

    onView(withId(R.id.price_value)).check(matches(withTextColor(R.color.black)));

    0 讨论(0)
提交回复
热议问题