Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a button is clickable in espresso test, android studio

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

like image 749
franck Avatar asked Oct 02 '15 12:10

franck


2 Answers

Why not? You can use isClickable() Matcher.

onView(withId(R.id.your_button)).check(matches(isClickable()));
like image 93
Ads Avatar answered Oct 07 '22 00:10

Ads


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)));
}
like image 37
Ezequiel García Avatar answered Oct 07 '22 00:10

Ezequiel García