Click On Not Fully Visible Imagebutton With Espresso
Solution 1:
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(
newViewAction() {
@OverridepublicMatcher<View> getConstraints() {
returnViewMatchers.isEnabled(); // no constraints, they are checked above
}
@OverridepublicStringgetDescription() {
return"click plus button";
}
@Overridepublicvoidperform(UiController uiController, View view) {
view.performClick();
}
}
);
Solution 2:
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.
Solution 3:
You have to scroll to the button before:
onView(withId(R.id.button_id)).perform(scrollTo(), click());
Solution 4:
This helped me to resolve button visibility while running my tests
publicstaticViewActionhandleConstraints(final ViewAction action, final Matcher<View> constraints)
{
returnnewViewAction()
{
@OverridepublicMatcher<View> getConstraints()
{
return constraints;
}
@OverridepublicStringgetDescription()
{
return action.getDescription();
}
@Overridepublicvoidperform(UiController uiController, View view)
{
action.perform(uiController, view);
}
};
}
publicvoidclickbutton()
{
onView(withId(r.id.button)).perform(handleConstraints(click(), isDisplayingAtLeast(65)));
}
Solution 5:
Default click of Espresso is requiring visibility of view > 90%
. What do you think about creating an own click
ViewAction?
Like this...
publicfinalclassMyViewActions {
publicstatic ViewAction click(){
returnnewGeneralClickAction(SafeTap.SINGLE, GeneralLocation.CENTER, Press.FINGER);
}
}
This click will click on the center of your view.
Then you could execute click like this:
onView(withId(....)).perform(MyViewActions.click());
I hope it could work.
Post a Comment for "Click On Not Fully Visible Imagebutton With Espresso"