问题
I am writing tests to determine that a specific button is not clickable or is clickable. However it seems to me that there isn't any method or maybe I can't find a method that can check this feature using Espresso. Can anyone help me ?
Thank you
回答1:
Why not? You can use isClickable() Matcher.
onView(withId(R.id.your_button)).check(matches(isClickable()));
回答2:
i always combine more tests for my button
@Test
public void buttonIsEnabled() {
onView(withId(R.id. your_button)).check(matches(isEnabled()));
}
@Test
public void buttonIsDisplayed() {
onView(withId(R.id. your_button)).check(matches(isDisplayed()));
}
@Test
public void buttonIsCompletelyDisplayed() {
onView(withId(R.id. your_button)).check(matches(isCompletelyDisplayed()));
}
@Test
public void buttonIsNotSelectable() {
onView(withId(R.id. your_button)).check(matches(not(isSelected())));
}
@Test
public void buttonIsClickable() {
onView(withId(R.id. your_button)).check(matches(not(isClickable())));
}
@Test
public void buttonWithText() {
onView(withId(R.id.your_button)).check(matches(withText(R.string.your_text)));
}
来源:https://stackoverflow.com/questions/32906881/checking-if-a-button-is-clickable-in-espresso-test-android-studio