osama-raddad/android-test-kit

GeneralSwipeAction doesn't use the exact start/endCoordinateProvider coordinates for down/up MotionEvent

Closed this issue · 4 comments

What steps will reproduce the problem?
Create a GeneralSwipeAction with a custom startCoordinatesProvider and 
endCoordinatesProvider

What is the expected output? What do you see instead?
I expect the the down MotionEvent to have the same x/y as the coordinates in 
startCoordinatesProvider, and the up MotionEvent to be the same as 
endCoordinatesProvider. The actual down and up coordinates ends up being 
slightly different.

What version of the product are you using? On what operating system?
1.1

Please provide any additional information below.
For my tests, I wanted to create a custom ViewAction that will precisely 
perform a drag from a given coordinate to another. So I wrote the following 
method:
   public static ViewAction drag(final float startX, final float startY, final float endX, final float endY) {
        CoordinatesProvider startCoordinates = new CoordinatesProvider() {
            @Override
            public float[] calculateCoordinates(View view) {
                return new float[] {startX, startY};
            }
        };
        CoordinatesProvider endCoordinates = new CoordinatesProvider() {
            @Override
            public float[] calculateCoordinates(View view) {
                return new float[] {endX, endY};
            }
        };
        return new GeneralSwipeAction(Swipe.FAST, startCoordinates, endCoordinates, Press.PINPOINT);
    }
When I ran this, my touchevent log shows that the down event x and y are 
slightly different than startX and startY. This seems to be due to how the 
swipe gesture is interpolated in 
https://code.google.com/p/android-test-kit/source/browse/espresso/lib/src/main/j
ava/com/google/android/apps/common/testing/ui/espresso/action/Swipe.java?r=c4e4d
a01ca8d0fab31129c87f525f6e9ba1ecc02  (line 54-57). Can you guys change the 
behavior so that the start/endCoordinateProvider does end up being down/up 
event coordinates?

Original issue reported on code.google.com by dav...@intrepid.io on 19 Nov 2014 at 4:25

Hi. We are having exactly the same issue. Espresso interpolates up to 10 points 
between start and end. But it seems to forget using the start and the end, and 
it only uses those intermediate points. 

I managed to make it work fine with this workaround that tweaks the start and 
end points forcing the interpolate function to have the original start and end 
points as the first and last interpolated points.


float newStart += (start - end) / 9;
float newEnd += start - end - 11 * (start - end) / 9;


(the calculations were deducted from the interpolate function)

Hope this helps.

Original comment by miguel.a...@gmail.com on 3 Dec 2014 at 3:45

Sorry, I made a mistake when pasting and translating my code:

float newStart = start;
float newEnd = end;
newStart += (start - end) / 9;
newEnd += start - end - 11 * (start - end) / 9;

I guess it can be simplified as:

float newStart = start + (start - end) / 9;
float newEnd = start - 11 * (start - end) / 9;

Best regards.

Original comment by miguel.a...@gmail.com on 3 Dec 2014 at 3:50

Original comment by vale...@google.com on 16 Dec 2014 at 10:25

  • Changed state: Accepted
Fixed in Espresso 2.0

Original comment by vale...@google.com on 20 Dec 2014 at 4:33

  • Changed state: Fixed