Testing background color espresso Android

前端 未结 7 993
灰色年华
灰色年华 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

    In my tests I have the following matcher for testing EditText color:

    public static Matcher withTextColor(final int color) {
        Checks.checkNotNull(color);
        return new BoundedMatcher(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)));
    

提交回复
热议问题