/** * Returns an action that clicks a descendant of the view matched with the given resource id. * * @param id resource id of the view to click. * @return an action that clicks a descendant of the view matched with the given resource id. */ public static ViewAction clickDescendantViewWithId(@IdRes final int id) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return hasDescendant(withId(id)); } @Override public String getDescription() { return "Click on a descendant view with id: " + id; } @Override public void perform(UiController uiController, View view) { GeneralClickAction action = new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER); View target = view.findViewById(id); // getConstraints() guarantees that the target never be null. action.perform(uiController, target); } }; }
/** * Returns an action that clicks a descendant of the view matched with the given resource id. */ public static ViewAction clickDescendantViewWithId(@IdRes final int id) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return hasDescendant(withId(id)); } @Override public String getDescription() { return "Click on a descendant view with id: " + id; } @Override public void perform(UiController uiController, View view) { GeneralClickAction action = new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER); View target = view.findViewById(id); // getConstraints() guarantees that the target never be null. action.perform(uiController, target); } }; }
/** * Custom ViewAction to click on dedicated coordinates * @param x - * @param y - * @return ViewAction - */ private 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; return new float[]{screenX, screenY}; } }, Press.FINGER); }
private 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); }
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); }
public static ViewAction clickPercent(final float pctX, final float pctY) { return new GeneralClickAction( Tap.SINGLE, view -> { final int[] screenPos = new int[2]; view.getLocationOnScreen(screenPos); int w = view.getWidth(); int h = view.getHeight(); float x = w * pctX; float y = h * pctY; final float screenX = screenPos[0] + x; final float screenY = screenPos[1] + y; return new float[]{screenX, screenY}; }, Press.FINGER); }
public static ViewAction clickXY(final int x, final int y){ return new GeneralClickAction( Tap.SINGLE, getCoordinatesProvider(x, y), Press.FINGER); }
public static ViewAction longClickXY(final int x, final int y){ return new GeneralClickAction( Tap.LONG, getCoordinatesProvider(x, y), Press.FINGER); }
public static ViewAction clickOnTop() { return new GeneralClickAction(Tap.SINGLE, GeneralLocation.TOP_CENTER, Press.FINGER); }
public static ViewAction clickOnChild(int childViewId) { return actionWithAssertions((new ChildClickAction( new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER), childViewId))); }
public ChildClickAction(GeneralClickAction generalClickAction, int childViewId) { mGeneralClickAction = generalClickAction; mChildViewId = childViewId; }