Click on not fully visible imageButton with Espresso

前端 未结 7 1134
臣服心动
臣服心动 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

    This helped me to resolve button visibility while running my tests

    public static ViewAction handleConstraints(final ViewAction action, final Matcher constraints)
    {
        return new ViewAction()
        {
            @Override
            public Matcher getConstraints()
            {
                return constraints;
            }
    
            @Override
            public String getDescription()
            {
                return action.getDescription();
            }
    
            @Override
            public void perform(UiController uiController, View view)
            {
                action.perform(uiController, view);
            }
        };
    }
    
    public void clickbutton()
    {
        onView(withId(r.id.button)).perform(handleConstraints(click(), isDisplayingAtLeast(65)));
    }
    

提交回复
热议问题