Skip to content

Commit 8522bb7

Browse files
committed
MultiGesture falls back to a regular single touch /perform when only one TouchAction is added to it. Fixes #33
1 parent 7df5d5b commit 8522bb7

File tree

5 files changed

+97
-2
lines changed

5 files changed

+97
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Locators:
6060
- findElementsByAndroidUIAutomator()
6161

6262
##Changelog##
63+
*github HEAD*
64+
- MultiGesture with a single TouchAction fixed for Android
65+
6366
*1.2.1*
6467
- fix dependency issue
6568

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.appium.java_client;
2+
3+
public class MissingParameterException extends IllegalArgumentException {
4+
5+
public MissingParameterException(String reason) {
6+
super(reason);
7+
}
8+
9+
public MissingParameterException(String reason, Throwable cause) {
10+
super(reason, cause);
11+
}
12+
13+
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,16 @@ public MultiTouchAction add(TouchAction action) {
6666
* Perform the multi-touch action on the mobile driver.
6767
*/
6868
public void perform() {
69-
driver.performMultiTouchAction(this);
69+
int size = actions.build().size();
70+
if (size > 1) {
71+
driver.performMultiTouchAction(this);
72+
} else if (size == 1) {
73+
//android doesn't like having multi-touch actions with only a single TouchAction...
74+
driver.performTouchAction((TouchAction)actions.build().get(0));
75+
} else {
76+
throw new MissingParameterException("MultiTouch action must have at least one TouchAction added before it can be performed");
77+
}
78+
7079
}
7180

7281
protected ImmutableMap getParameters() {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
+Copyright 2014 Appium contributors
3+
+Copyright 2014 Software Freedom Conservancy
4+
+
5+
+Licensed under the Apache License, Version 2.0 (the "License");
6+
+you may not use this file except in compliance with the License.
7+
+You may obtain a copy of the License at
8+
+
9+
+ http://www.apache.org/licenses/LICENSE-2.0
10+
+
11+
+Unless required by applicable law or agreed to in writing, software
12+
+distributed under the License is distributed on an "AS IS" BASIS,
13+
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
+See the License for the specific language governing permissions and
15+
+limitations under the License.
16+
+ */
17+
18+
package io.appium.java_client;
19+
20+
import org.junit.After;
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.openqa.selenium.remote.CapabilityType;
24+
import org.openqa.selenium.remote.DesiredCapabilities;
25+
26+
import java.io.File;
27+
import java.net.URL;
28+
29+
/**
30+
* Test Mobile Driver features
31+
*/
32+
public class AndroidGestureTest {
33+
private AppiumDriver driver;
34+
35+
@Before
36+
public void setup() throws Exception {
37+
File appDir = new File("src/test/java/io/appium/java_client");
38+
File app = new File(appDir, "ApiDemos-debug.apk");
39+
DesiredCapabilities capabilities = new DesiredCapabilities();
40+
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
41+
capabilities.setCapability("device", "Android");
42+
capabilities.setCapability("app", app.getAbsolutePath());
43+
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
44+
}
45+
46+
@After
47+
public void tearDown() throws Exception {
48+
driver.quit();
49+
}
50+
51+
@Test
52+
public void MultiGestureSingleActionTest() throws InterruptedException {
53+
//the underlying java library for Appium doesn't like multi-gestures with only a single action.
54+
//but java-client should handle it, silently falling back to just performing a single action.
55+
56+
MultiTouchAction multiTouch = new MultiTouchAction(driver);
57+
TouchAction action0 = new TouchAction(driver).tap(100,300);
58+
multiTouch.add(action0).perform();
59+
}
60+
61+
@Test
62+
public void TapSingleFingerTest() {
63+
driver.tap(1,100,200,1000);
64+
}
65+
}

src/test/java/io/appium/java_client/MobileDriverGestureTest.java renamed to src/test/java/io/appium/java_client/iOSGestureTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/**
3434
* Test Mobile Driver features
3535
*/
36-
public class MobileDriverGestureTest {
36+
public class iOSGestureTest {
3737

3838
private AppiumDriver driver;
3939

@@ -119,4 +119,9 @@ public void ZoomTest() throws InterruptedException {
119119
driver.zoom(mapview);
120120
Thread.sleep(2000);
121121
}
122+
123+
@Test
124+
public void TapSingleFingerTest() {
125+
driver.tap(1,100,200,1000);
126+
}
122127
}

0 commit comments

Comments
 (0)