From da8d7f80734942ca47c0471862209013aa3a0fd4 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 19 Dec 2017 20:56:06 +0100 Subject: [PATCH 1/3] Remove isPositive verification for point coordinates --- .../io/appium/java_client/touch/offset/PointOption.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/appium/java_client/touch/offset/PointOption.java b/src/main/java/io/appium/java_client/touch/offset/PointOption.java index 9eeaaecd9..24c2dceb2 100644 --- a/src/main/java/io/appium/java_client/touch/offset/PointOption.java +++ b/src/main/java/io/appium/java_client/touch/offset/PointOption.java @@ -1,7 +1,5 @@ package io.appium.java_client.touch.offset; -import static com.google.common.base.Preconditions.checkArgument; -import static java.lang.String.format; import static java.util.Optional.ofNullable; import io.appium.java_client.touch.ActionOptions; @@ -13,8 +11,6 @@ public class PointOption> extends ActionOptions { protected Point coordinates; - private static final String ERROR_MESSAGE_TEMPLATE = "%s coordinate value should be equal or greater than zero"; - /** * It creates a built instance of {@link PointOption} which takes x and y coordinates. * This is offset from the upper left corner of the screen. @@ -36,14 +32,14 @@ public static PointOption point(int xOffset, int yOffset) { * @return self-reference */ public T withCoordinates(int xOffset, int yOffset) { - checkArgument(xOffset >= 0, format(ERROR_MESSAGE_TEMPLATE, "X")); - checkArgument(yOffset >= 0, format(ERROR_MESSAGE_TEMPLATE, "Y")); coordinates = new Point(xOffset, yOffset); + //noinspection unchecked return (T) this; } @Override protected void verify() { + //noinspection ResultOfMethodCallIgnored ofNullable(coordinates).orElseThrow(() -> new IllegalArgumentException( "Coordinate values must be defined")); } From e853e244b3fc4d20a4142877af04f6d8a6a66d5f Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 19 Dec 2017 20:57:06 +0100 Subject: [PATCH 2/3] Update tests --- .../java/io/appium/java_client/touch/TouchOptionsTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java b/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java index 9822b0c9e..7faf773f5 100644 --- a/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java +++ b/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java @@ -44,8 +44,6 @@ public void invalidOptionsArgumentsShouldFailOnAltering() throws Exception { final List invalidOptions = new ArrayList<>(); invalidOptions.add(() -> waitOptions(ofMillis(-1))); invalidOptions.add(() -> new ElementOption().withCoordinates(0, 0).withElement(null)); - invalidOptions.add(() -> new PointOption().withCoordinates(0, -1)); - invalidOptions.add(() -> new PointOption().withCoordinates(-1, 0)); invalidOptions.add(() -> new WaitOptions().withDuration(null)); invalidOptions.add(() -> tapOptions().withTapsCount(-1)); invalidOptions.add(() -> longPressOptions().withDuration(null)); From a2d84103994a8a8a1d1c50b058ef8a049f29e3b0 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 19 Dec 2017 21:05:48 +0100 Subject: [PATCH 3/3] Add an explanation to the documentation --- src/main/java/io/appium/java_client/TouchAction.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/io/appium/java_client/TouchAction.java b/src/main/java/io/appium/java_client/TouchAction.java index cc27ed8e2..ba88d8f91 100644 --- a/src/main/java/io/appium/java_client/TouchAction.java +++ b/src/main/java/io/appium/java_client/TouchAction.java @@ -125,6 +125,11 @@ public T release() { * Moves current touch to a new position. * * @param moveToOptions see {@link PointOption} and {@link ElementOption} + * Important: some older Appium drivers releases have a bug when moveTo + * coordinates are calculated as relative to the recent pointer position + * in the chain instead of being absolute. + * @see Appium Issue #7486 + * for more details. * @return this TouchAction, for chaining. */ public T moveTo(PointOption moveToOptions) {