Skip to content

Commit 0de6e0d

Browse files
saikrishna321SrinivasanTarget
authored andcommitted
added gesture test (appium-boneyard#129)
* added gesture test * fixed reviews
1 parent 1555fd2 commit 0de6e0d

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/BaseCrossPlatformDriver.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import io.appium.java_client.AppiumDriver;
44
import io.appium.java_client.MobileBy;
5+
import io.appium.java_client.MobileElement;
6+
import io.appium.java_client.TouchAction;
57
import io.appium.java_client.android.AndroidDriver;
68
import io.appium.java_client.ios.IOSDriver;
79
import io.appium.java_client.service.local.AppiumDriverLocalService;
810
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
911
import org.junit.After;
1012
import org.junit.Before;
13+
import org.openqa.selenium.Dimension;
1114
import org.openqa.selenium.remote.DesiredCapabilities;
1215
import org.openqa.selenium.support.ui.ExpectedConditions;
1316
import org.openqa.selenium.support.ui.WebDriverWait;
@@ -17,7 +20,7 @@
1720

1821

1922
public class BaseCrossPlatformDriver {
20-
public AppiumDriver driver;
23+
public AppiumDriver<MobileElement> driver;
2124
private static AppiumDriverLocalService service;
2225

2326
@Before
@@ -72,4 +75,14 @@ public void login() {
7275
new WebDriverWait(driver, 30).until(ExpectedConditions.
7376
elementToBeClickable(MobileBy.AccessibilityId("login"))).click();
7477
}
78+
79+
public void verticalSwipe(String locator) throws InterruptedException {
80+
Thread.sleep(3000);
81+
MobileElement slider = driver.findElementByAccessibilityId(locator);
82+
Dimension size = slider.getSize();
83+
84+
TouchAction swipe = new TouchAction(driver).press(slider, size.width / 2, size.height - 20)
85+
.waitAction(2000).moveTo(slider,size.width / 2, size.height / 2 + 50).release();
86+
swipe.perform();
87+
}
7588
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.saucelabs.appium;
2+
3+
import io.appium.java_client.MobileBy;
4+
import io.appium.java_client.MobileElement;
5+
import io.appium.java_client.TouchAction;
6+
import io.appium.java_client.ios.IOSTouchAction;
7+
import org.junit.Test;
8+
import org.openqa.selenium.Alert;
9+
import org.openqa.selenium.Dimension;
10+
import org.openqa.selenium.support.ui.ExpectedConditions;
11+
import org.openqa.selenium.support.ui.WebDriverWait;
12+
13+
import static org.junit.Assert.assertTrue;
14+
15+
public class GestureTest extends BaseCrossPlatformDriver{
16+
17+
@Test
18+
public void horizontalSwipingTest() throws Exception {
19+
login();
20+
driver.findElementByAccessibilityId("slider1").click();
21+
MobileElement slider = driver.findElementByAccessibilityId("slider");
22+
Dimension size = slider.getSize();
23+
24+
TouchAction swipe = new TouchAction(driver).press(slider, 0, size.height / 2).waitAction(2000)
25+
.moveTo(slider, size.width / 2, size.height / 2).release();
26+
swipe.perform();
27+
}
28+
29+
@Test //Will work only on XCUI mode as doubleTap is not supported by IOS/Android
30+
public void doubleTap() throws InterruptedException {
31+
login();
32+
driver.findElementByAccessibilityId("doubleTap").click();
33+
MobileElement doubleTap = (MobileElement) new WebDriverWait(driver, 30).
34+
until(ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("doubleTapMe")));
35+
new IOSTouchAction(driver).doubleTap(doubleTap).perform();
36+
Thread.sleep(2000);
37+
assertTrue(driver.switchTo().alert().getText().contains("Double tap successful!"));
38+
}
39+
40+
@Test
41+
public void longPress() throws InterruptedException {
42+
login();
43+
Thread.sleep(5000);
44+
driver.findElementByAccessibilityId("longPress").click();
45+
MobileElement longpress = (MobileElement) new WebDriverWait(driver, 30).
46+
until(ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("longpress")));
47+
new TouchAction(driver).longPress(longpress,3000).perform();
48+
assertTrue(driver.switchTo().alert().getText().contains("Long Pressed"));
49+
}
50+
}

0 commit comments

Comments
 (0)