Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso test, click X/Y coordinates

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.

like image 424
Pulkit Avatar asked Oct 28 '15 03:10

Pulkit


People also ask

How do you check espresso visibility?

One simple way to check for a View or its subclass like a Button is to use method getVisibility from View class.


1 Answers

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);
}
like image 97
JeKa Avatar answered Sep 20 '22 00:09

JeKa