Skip to content

Commit 08fe157

Browse files
Merge pull request #663 from mykola-mokhnach/clear_touch
Clear existing actions/parameters after perform is invoked
2 parents f675f14 + 36974a1 commit 08fe157

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/main/java/io/appium/java_client/MultiTouchAction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,14 @@ protected ImmutableMap<String, ImmutableList<Object>> getParameters() {
8585
});
8686
return ImmutableMap.of("actions", listOfActionChains.build());
8787
}
88+
89+
/**
90+
* Clears all the existing touch actions and resets the instance to the initial state.
91+
*
92+
* @return this MultiTouchAction, for possible segmented-touches.
93+
*/
94+
protected MultiTouchAction clearActions() {
95+
actions = ImmutableList.builder();
96+
return this;
97+
}
8898
}

src/main/java/io/appium/java_client/PerformsTouchActions.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public interface PerformsTouchActions extends ExecutesMethod {
2929
* https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html
3030
* It's more convenient to call the perform() method of the TouchAction
3131
* object itself.
32+
* All the existing touch action parameters will be wiped out after this method
33+
* is called.
3234
*
3335
* @param touchAction A TouchAction object, which contains a list of individual
3436
* touch actions to perform
@@ -37,7 +39,7 @@ public interface PerformsTouchActions extends ExecutesMethod {
3739
default TouchAction performTouchAction(TouchAction touchAction) {
3840
ImmutableMap<String, ImmutableList<Object>> parameters = touchAction.getParameters();
3941
execute(PERFORM_TOUCH_ACTION, parameters);
40-
return touchAction;
42+
return touchAction.clearParameters();
4143
}
4244

4345
/**
@@ -46,11 +48,14 @@ default TouchAction performTouchAction(TouchAction touchAction) {
4648
* https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html
4749
* It's more convenient to call the perform() method of the MultiTouchAction
4850
* object.
51+
* All the existing multi touch actions will be wiped out after this method
52+
* is called.
4953
*
5054
* @param multiAction the MultiTouchAction object to perform.
5155
*/
5256
default void performMultiTouchAction(MultiTouchAction multiAction) {
5357
ImmutableMap<String, ImmutableList<Object>> parameters = multiAction.getParameters();
5458
execute(PERFORM_MULTI_TOUCH, parameters);
59+
multiAction.clearActions();
5560
}
5661
}

src/main/java/io/appium/java_client/TouchAction.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,14 @@ protected ImmutableMap<String, ImmutableList<Object>> getParameters() {
340340
return ImmutableMap.of("actions", parameters.build());
341341
}
342342

343-
protected void clearParameters() {
343+
/**
344+
* Clears all the existing action parameters and resets the instance to the initial state.
345+
*
346+
* @return this TouchAction, for possible segmented-touches.
347+
*/
348+
protected TouchAction clearParameters() {
344349
parameterBuilder = ImmutableList.builder();
350+
return this;
345351
}
346352

347353
/**

0 commit comments

Comments
 (0)