From 36974a1f6eeabfad8394ccac9a9e09d60a95eab7 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 26 Jun 2017 13:56:38 +0200 Subject: [PATCH] Clear existing actions/parameters after perform is invoked --- .../java/io/appium/java_client/MultiTouchAction.java | 10 ++++++++++ .../io/appium/java_client/PerformsTouchActions.java | 7 ++++++- src/main/java/io/appium/java_client/TouchAction.java | 8 +++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/appium/java_client/MultiTouchAction.java b/src/main/java/io/appium/java_client/MultiTouchAction.java index cd85304a6..f2a3e08be 100644 --- a/src/main/java/io/appium/java_client/MultiTouchAction.java +++ b/src/main/java/io/appium/java_client/MultiTouchAction.java @@ -85,4 +85,14 @@ protected ImmutableMap> getParameters() { }); return ImmutableMap.of("actions", listOfActionChains.build()); } + + /** + * Clears all the existing touch actions and resets the instance to the initial state. + * + * @return this MultiTouchAction, for possible segmented-touches. + */ + protected MultiTouchAction clearActions() { + actions = ImmutableList.builder(); + return this; + } } diff --git a/src/main/java/io/appium/java_client/PerformsTouchActions.java b/src/main/java/io/appium/java_client/PerformsTouchActions.java index 0a3056730..2f01246eb 100644 --- a/src/main/java/io/appium/java_client/PerformsTouchActions.java +++ b/src/main/java/io/appium/java_client/PerformsTouchActions.java @@ -29,6 +29,8 @@ public interface PerformsTouchActions extends ExecutesMethod { * https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html * It's more convenient to call the perform() method of the TouchAction * object itself. + * All the existing touch action parameters will be wiped out after this method + * is called. * * @param touchAction A TouchAction object, which contains a list of individual * touch actions to perform @@ -37,7 +39,7 @@ public interface PerformsTouchActions extends ExecutesMethod { default TouchAction performTouchAction(TouchAction touchAction) { ImmutableMap> parameters = touchAction.getParameters(); execute(PERFORM_TOUCH_ACTION, parameters); - return touchAction; + return touchAction.clearParameters(); } /** @@ -46,11 +48,14 @@ default TouchAction performTouchAction(TouchAction touchAction) { * https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html * It's more convenient to call the perform() method of the MultiTouchAction * object. + * All the existing multi touch actions will be wiped out after this method + * is called. * * @param multiAction the MultiTouchAction object to perform. */ default void performMultiTouchAction(MultiTouchAction multiAction) { ImmutableMap> parameters = multiAction.getParameters(); execute(PERFORM_MULTI_TOUCH, parameters); + multiAction.clearActions(); } } diff --git a/src/main/java/io/appium/java_client/TouchAction.java b/src/main/java/io/appium/java_client/TouchAction.java index e05d8effd..ca30fde11 100644 --- a/src/main/java/io/appium/java_client/TouchAction.java +++ b/src/main/java/io/appium/java_client/TouchAction.java @@ -340,8 +340,14 @@ protected ImmutableMap> getParameters() { return ImmutableMap.of("actions", parameters.build()); } - protected void clearParameters() { + /** + * Clears all the existing action parameters and resets the instance to the initial state. + * + * @return this TouchAction, for possible segmented-touches. + */ + protected TouchAction clearParameters() { parameterBuilder = ImmutableList.builder(); + return this; } /**