I'm trying to get button background color with the help of this Matcher.
public static Matcher<View> withButtonColor(int expectedColor) {
return new BoundedMatcher<View, Button>(Button.class) {
@Override
public boolean matchesSafely(Button button) {
int actualColor = 0;
try {
actualColor = ContextCompat.getColor(currentActivity.getBaseContext(), expectedColor);
} catch (Exception e) {
e.printStackTrace();
}
return expectedColor == actualColor;
}
@Override
public void describeTo(Description description) {
description.appendText("ERROR");
}
};
}
Using
onView(withId(trueButton)).check(matches(withButtonColor(ActivityPage.greenColor)));
Nothing helps though.
I pass a valid color as an argument, though actual color always equals 0 anyway. I guess there might be a problem with getting context.
Aucun commentaire:
Enregistrer un commentaire