|
| 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