Skip to content

Commit e3d7390

Browse files
committed
DoubleTap Support
1 parent 0e9746b commit e3d7390

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,22 @@ public void performMultiTouchAction(
395395

396396
multiTouch.perform();
397397
}
398+
399+
/**
400+
* Double taps element
401+
*/
402+
public void doubleTap(WebElement element, int x, int y) {
403+
TouchAction action = new TouchAction(this);
404+
action.doubleTap(element, x, y).perform();
405+
}
406+
407+
/**
408+
* Double taps element
409+
*/
410+
public void doubleTap(WebElement element) {
411+
TouchAction action = new TouchAction(this);
412+
action.doubleTap(element).perform();
413+
}
398414

399415
/**
400416
* @see TouchShortcuts#tap(int, int, int, int).

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,37 @@ public TouchAction tap(WebElement el, int x, int y) {
184184
parameterBuilder.add(action);
185185
return this;
186186
}
187+
188+
/**
189+
* Double taps an element, offset from upper left corner.
190+
*
191+
* @param el element to tap.
192+
* @param x x offset.
193+
* @param y y offset.
194+
* @return this TouchAction, for chaining.
195+
*/
196+
public TouchAction doubleTap(WebElement el, int x, int y) {
197+
ActionParameter action = new ActionParameter("doubleTap", (HasIdentity) el);
198+
action.addParameter("x", x);
199+
action.addParameter("y", y);
200+
parameterBuilder.add(action);
201+
return this;
202+
}
187203

204+
/**
205+
* Double taps an element, offset from upper left corner.
206+
*
207+
* @param el element to tap.
208+
* @param x x offset.
209+
* @param y y offset.
210+
* @return this TouchAction, for chaining.
211+
*/
212+
public TouchAction doubleTap(WebElement el) {
213+
ActionParameter action = new ActionParameter("doubleTap", (HasIdentity) el);
214+
parameterBuilder.add(action);
215+
return this;
216+
}
217+
188218
/**
189219
* A wait action, used as a NOP in multi-chaining.
190220
*

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ public interface TouchShortcuts {
4848
* @param el The element to pinch.
4949
*/
5050
void zoom(WebElement el);
51+
52+
/**
53+
* Convenience method for double tapping element at a coordinate
54+
*
55+
* @param element
56+
* @param x
57+
* @param y
58+
*/
59+
void doubleTap(WebElement element, int x, int y);
60+
61+
/**
62+
* Convenience method for double tapping center of an element
63+
*
64+
* @param element
65+
* @param x
66+
* @param y
67+
*/
68+
void doubleTap(WebElement element);
5169

5270
/**
5371
* Convenience method for tapping a position on the screen.

src/test/java/io/appium/java_client/android/AndroidGestureTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNotEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertTrue;
2123

2224
import io.appium.java_client.MobileBy;
2325
import io.appium.java_client.MobileElement;
@@ -40,6 +42,15 @@ public class AndroidGestureTest extends BaseAndroidTest {
4042
.findElementById("io.appium.android.apis:id/button_toggle").getText());
4143
}
4244

45+
@Test public void doubleTapTest() throws Exception {
46+
driver.startActivity("io.appium.android.apis", ".view.TextSwitcher1");
47+
String textBeforeDoubleTap = (driver.findElementByClassName("android.widget.TextView")).getText();
48+
AndroidElement next = driver.findElementById("io.appium.android.apis:id/next");
49+
String textAfterDoubleTap = (driver.findElementByClassName("android.widget.TextView")).getText();
50+
assertFalse(textBeforeDoubleTap.equals(textAfterDoubleTap));
51+
assertTrue(textAfterDoubleTap.equals("2"));
52+
}
53+
4354
@Test public void singleElementTapTest() throws Exception {
4455
driver.startActivity("io.appium.android.apis", ".view.Buttons1");
4556
driver.tap(1, driver.findElementById("io.appium.android.apis:id/button_toggle"), 1000);

src/test/java/io/appium/java_client/ios/IOSGesturesTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.appium.java_client.ios;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
2021

2122
import io.appium.java_client.MobileElement;
2223
import io.appium.java_client.SwipeElementDirection;
@@ -33,6 +34,14 @@ public class IOSGesturesTest extends BaseIOSTest {
3334
driver.tap(2, e, 2000);
3435
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
3536
}
37+
38+
@Test public void doubleTapTest() {
39+
IOSElement firstField = (IOSElement) driver.findElementById("IntegerA");
40+
firstField.sendKeys("2");
41+
driver.doubleTap(firstField);
42+
IOSElement editingMenu = (IOSElement) driver.findElementByClassName("UIAEditingMenu");
43+
assertNotNull(editingMenu);
44+
}
3645

3746
@Test public void zoomTest() {
3847
MobileElement e = driver.findElementById("IntegerA");

0 commit comments

Comments
 (0)