Espresso test, click X/Y coordinates

狂风中的少年 提交于 2019-12-12 18:29:40

问题


Any idea how to do this for android? I can't seem to create a method that actually clicks.

I know you can do it with onview, but I just want an x/y position.


回答1:


The answer is already given here.

public static ViewAction clickXY(final int x, final int y){
    return new GeneralClickAction(
        Tap.SINGLE,
        new CoordinatesProvider() {
            @Override
            public float[] calculateCoordinates(View view) {

               final int[] screenPos = new int[2];
               view.getLocationOnScreen(screenPos);

               final float screenX = screenPos[0] + x;
               final float screenY = screenPos[1] + y;
               float[] coordinates = {screenX, screenY};

               return coordinates;
            }
        },
        Press.FINGER);
}


来源:https://stackoverflow.com/questions/33382344/espresso-test-click-x-y-coordinates

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