Checking the ability to press a button in an espresso test, android studio

I am writing tests to determine that a particular button is not clickable or clickable. However, it seems to me that there is no method, or maybe I can not find a method that can test this function using Espresso. Can anybody help me?

thanks

+4
source share
2 answers

Why not? You can use isClickable () Matcher.

onView(withId(R.id.your_button)).check(matches(isClickable()));
+5
source

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)));
}
+3
source

Source: https://habr.com/ru/post/1609962/


All Articles