Click on not fully visible imageButton with Espresso

前端 未结 7 1098
臣服心动
臣服心动 2021-01-31 09:05

I have a custom ImageButton that is not fully visible, by design, so when I perform a click action I get this error:

android.support.test.espresso.P         


        
7条回答
  •  囚心锁ツ
    2021-01-31 09:34

    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 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();
                    }
                }
        );
    

提交回复
热议问题