【发布时间】:2020-10-22 14:20:48
【问题描述】:
我正在尝试借助此 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");
}
};
}
使用
onView(withId(trueButton)).check(matches(withButtonColor(ActivityPage.greenColor)));
但没有任何帮助。
我传递了一个有效的颜色作为参数,尽管实际颜色总是等于 0。 我想获取上下文可能有问题。
【问题讨论】:
标签: android testing automated-tests android-espresso