Skip to content

Commit 7b0d0b8

Browse files
committed
DoubleTap Support
1 parent 0e9746b commit 7b0d0b8

File tree

6 files changed

+82
-1
lines changed

6 files changed

+82
-1
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
@@ -382,6 +382,22 @@ public void performMultiTouchAction(
382382
ImmutableMap<String, ImmutableList> parameters = multiAction.getParameters();
383383
execute(PERFORM_MULTI_TOUCH, parameters);
384384
}
385+
386+
/**
387+
* @see TouchShortcuts#doubleTap(WebElement, int, int).
388+
*/
389+
@Override public void doubleTap(WebElement element, int x, int y) {
390+
TouchAction action = new TouchAction(this);
391+
action.doubleTap(element, x, y).perform();
392+
}
393+
394+
/**
395+
* @see TouchShortcuts#doubleTap(WebElement).
396+
*/
397+
@Override public void doubleTap(WebElement element) {
398+
TouchAction action = new TouchAction(this);
399+
action.doubleTap(element).perform();
400+
}
385401

386402
/**
387403
* @see TouchShortcuts#tap(int, WebElement, int).

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,35 @@ 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+
* @return this TouchAction, for chaining.
209+
*/
210+
public TouchAction doubleTap(WebElement el) {
211+
ActionParameter action = new ActionParameter("doubleTap", (HasIdentity) el);
212+
parameterBuilder.add(action);
213+
return this;
214+
}
215+
188216
/**
189217
* A wait action, used as a NOP in multi-chaining.
190218
*

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ 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 we want to double tap.
56+
* @param x x coordinate.
57+
* @param y y coordinate.
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 we want to double tap.
65+
*/
66+
void doubleTap(WebElement element);
5167

5268
/**
5369
* Convenience method for tapping a position on the screen.

src/main/java/org/openqa/selenium/WebDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
package org.openqa.selenium;
1919

20-
import org.openqa.selenium.logging.Logs;
2120
import org.openqa.selenium.logging.LoggingPreferences;
21+
import org.openqa.selenium.logging.Logs;
2222

2323
import java.net.URL;
2424
import java.util.List;

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

Lines changed: 12 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,16 @@ 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+
driver.doubleTap(next);
50+
String textAfterDoubleTap = (driver.findElementByClassName("android.widget.TextView")).getText();
51+
assertFalse(textBeforeDoubleTap.equals(textAfterDoubleTap));
52+
assertTrue("2".equals(textAfterDoubleTap));
53+
}
54+
4355
@Test public void singleElementTapTest() throws Exception {
4456
driver.startActivity("io.appium.android.apis", ".view.Buttons1");
4557
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)