Click on not fully visible imageButton with Espresso
I don't think there is any easy, elegant solution to this. The 90% constraint is hardcoded in GeneralClickAction
, and the class is final so we can't override getConstraints
.
I would write your own ViewAction based on GeneralClickAction
's code, skipping the isDisplayingAtLeast
check.
None of the above worked for me. Here is a custom matcher that completely removes that constraint and allows you to click on the view
onView(withId(yourID)).check(matches(allOf( isEnabled(), isClickable()))).perform(
new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isEnabled(); // no constraints, they are checked above
}
@Override
public String getDescription() {
return "click plus button";
}
@Override
public void perform(UiController uiController, View view) {
view.performClick();
}
}
);