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

喜你入骨 提交于 2020-01-13 10:15:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!