Skip to content

Commit

Permalink
Merge pull request wix#1854 from wix/robust-tapAtPoint-android
Browse files Browse the repository at this point in the history
(Android) Apply existing tap improvements and adjustments to tapAtPoint()
  • Loading branch information
d4vidi authored Jan 13, 2020
2 parents df8586d + 4a4d67c commit 53cd484
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.wix.detox.espresso;

import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;

import com.wix.detox.espresso.DetoxErrors.DetoxRuntimeException;
import com.wix.detox.espresso.DetoxErrors.StaleActionException;
import com.wix.detox.espresso.action.RNClickAction;
import com.wix.detox.espresso.common.annot.MotionDir;
import com.wix.detox.espresso.scroll.ScrollEdgeException;
import com.wix.detox.espresso.scroll.ScrollHelper;
Expand All @@ -20,7 +19,6 @@
import androidx.test.espresso.action.GeneralSwipeAction;
import androidx.test.espresso.action.Press;
import androidx.test.espresso.action.Swipe;
import androidx.test.espresso.action.Tap;

import static androidx.test.espresso.action.ViewActions.actionWithAssertions;
import static androidx.test.espresso.action.ViewActions.swipeDown;
Expand Down Expand Up @@ -61,12 +59,10 @@ public float[] calculateCoordinates(View view) {
view.getLocationOnScreen(xy);
final float fx = xy[0] + px;
final float fy = xy[1] + py;
float[] coordinates = {fx, fy};
return coordinates;
return new float[] {fx, fy};
}
};
return actionWithAssertions(new GeneralClickAction(
Tap.SINGLE, c, Press.FINGER, InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY));
return actionWithAssertions(new RNClickAction(c));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,33 @@

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.action.CoordinatesProvider;
import androidx.test.espresso.action.GeneralClickAction;
import androidx.test.espresso.action.GeneralLocation;
import androidx.test.espresso.action.Press;

import static androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast;

public class RNClickAction implements ViewAction {
private final GeneralClickAction clickAction =
new GeneralClickAction(
new DetoxSingleTap(),
GeneralLocation.VISIBLE_CENTER,
Press.FINGER,
InputDevice.SOURCE_UNKNOWN,
MotionEvent.BUTTON_PRIMARY);
private final GeneralClickAction clickAction;

public RNClickAction() {
clickAction = new GeneralClickAction(
new DetoxSingleTap(),
GeneralLocation.VISIBLE_CENTER,
Press.FINGER,
InputDevice.SOURCE_UNKNOWN,
MotionEvent.BUTTON_PRIMARY);
}

public RNClickAction(CoordinatesProvider coordinatesProvider) {
clickAction = new GeneralClickAction(
new DetoxSingleTap(),
coordinatesProvider,
Press.FINGER,
InputDevice.SOURCE_UNKNOWN,
MotionEvent.BUTTON_PRIMARY);
}

@Override
public Matcher<View> getConstraints() {
Expand Down

0 comments on commit 53cd484

Please sign in to comment.