From 0dc816c14cee6b3a3496a5c9f4959098bb3283df Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Wed, 4 Mar 2015 00:45:57 +0400 Subject: [PATCH 1/3] #160 Enum SwipeElementDirection is redesigned. I have to redesign coordinate calculation and add the new swipe-method to MobileElement. --- .../IllegalCoordinatesException.java | 12 ++ .../io/appium/java_client/MobileElement.java | 2 +- .../java_client/SwipeElementDirection.java | 124 ++++++++++-------- 3 files changed, 80 insertions(+), 58 deletions(-) create mode 100644 src/main/java/io/appium/java_client/IllegalCoordinatesException.java diff --git a/src/main/java/io/appium/java_client/IllegalCoordinatesException.java b/src/main/java/io/appium/java_client/IllegalCoordinatesException.java new file mode 100644 index 000000000..2325ced64 --- /dev/null +++ b/src/main/java/io/appium/java_client/IllegalCoordinatesException.java @@ -0,0 +1,12 @@ +package io.appium.java_client; + +import org.openqa.selenium.WebDriverException; + +public class IllegalCoordinatesException extends WebDriverException { + private static final long serialVersionUID = 1L; + + public IllegalCoordinatesException(String message) { + super(message); + } + +} diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 54ffbe4bc..133e3b216 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -70,6 +70,6 @@ public void zoom() { @Override public void swipe(SwipeElementDirection direction, int duration) { - direction.swipe((AppiumDriver) parent, this, duration); + direction.swipe((AppiumDriver) parent, this, 0, 0, 0, 0, duration); } } diff --git a/src/main/java/io/appium/java_client/SwipeElementDirection.java b/src/main/java/io/appium/java_client/SwipeElementDirection.java index 85c20d203..06a9f867f 100644 --- a/src/main/java/io/appium/java_client/SwipeElementDirection.java +++ b/src/main/java/io/appium/java_client/SwipeElementDirection.java @@ -1,57 +1,67 @@ -package io.appium.java_client; - -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; - -public enum SwipeElementDirection { - /** - * Up from the center of the lower - */ - UP{ - @Override - void swipe(AppiumDriver driver, MobileElement element, int duration){ - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(p.getX(), location.getY() + size.getHeight(), p.getX(), location.getY(), duration); - } - }, - /** - * Down from the center of the upper - */ - DOWN{ - @Override - void swipe(AppiumDriver driver, MobileElement element, int duration){ - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(p.getX(), location.getY(), p.getX(), location.getY() + size.getHeight(), duration); - } - }, - /** - * To the left from the center of the rightmost - */ - LEFT{ - @Override - void swipe(AppiumDriver driver, MobileElement element, int duration){ - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(location.getX() + size.getWidth(), p.getY(), location.getX(), p.getY(), duration); - } - }, - /** - * To the right from the center of the leftmost - */ - RIGHT{ - @Override - void swipe(AppiumDriver driver, MobileElement element, int duration){ - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(location.getX(), p.getY(), location.getX()+ size.getWidth(), p.getY(), duration); - } - }; - - void swipe(AppiumDriver driver, MobileElement element, int duration){} -} +package io.appium.java_client; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; + +public enum SwipeElementDirection { + /** + * Up from the center of the lower + */ + UP{ + @Override + void swipe(AppiumDriver driver, MobileElement element, + int xOffsetStart, int xOffsetEnd, int yOffsetStart, + int yOffsetEnd, int duration) throws IllegalCoordinatesException { + Point p = element.getCenter(); + Point location = element.getLocation(); + Dimension size = element.getSize(); + driver.swipe(p.getX(), location.getY() + size.getHeight(), p.getX(), location.getY(), duration); + } + }, + /** + * Down from the center of the upper + */ + DOWN{ + @Override + void swipe(AppiumDriver driver, MobileElement element, + int xOffsetStart, int xOffsetEnd, int yOffsetStart, + int yOffsetEnd, int duration) throws IllegalCoordinatesException { + Point p = element.getCenter(); + Point location = element.getLocation(); + Dimension size = element.getSize(); + driver.swipe(p.getX(), location.getY(), p.getX(), location.getY() + size.getHeight(), duration); + } + }, + /** + * To the left from the center of the rightmost + */ + LEFT{ + @Override + void swipe(AppiumDriver driver, MobileElement element, + int xOffsetStart, int xOffsetEnd, int yOffsetStart, + int yOffsetEnd, int duration) throws IllegalCoordinatesException { + Point p = element.getCenter(); + Point location = element.getLocation(); + Dimension size = element.getSize(); + driver.swipe(location.getX() + size.getWidth(), p.getY(), location.getX(), p.getY(), duration); + } + }, + /** + * To the right from the center of the leftmost + */ + RIGHT{ + @Override + void swipe(AppiumDriver driver, MobileElement element, + int xOffsetStart, int xOffsetEnd, int yOffsetStart, + int yOffsetEnd, int duration) throws IllegalCoordinatesException { + Point p = element.getCenter(); + Point location = element.getLocation(); + Dimension size = element.getSize(); + driver.swipe(location.getX(), p.getY(), location.getX()+ size.getWidth(), p.getY(), duration); + } + }; + + abstract void swipe(AppiumDriver driver, MobileElement element, + int xOffsetStart, int xOffsetEnd, int yOffsetStart, + int yOffsetEnd, int duration) throws IllegalCoordinatesException; +} From 166a0cbdd2826e7af71cd1ed37d959568464fc4e Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Fri, 6 Mar 2015 00:59:12 +0400 Subject: [PATCH 2/3] #160 is fixed --- .../io/appium/java_client/MobileElement.java | 8 +- .../java_client/SwipeElementDirection.java | 184 +++++++++-- .../appium/java_client/TouchableElement.java | 128 ++++---- .../android/AndroidGestureTest.java | 255 ++++++++------- .../java_client/ios/iOSGestureTest.java | 294 +++++++++--------- 5 files changed, 523 insertions(+), 346 deletions(-) diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 133e3b216..e4d8b526e 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -70,6 +70,12 @@ public void zoom() { @Override public void swipe(SwipeElementDirection direction, int duration) { - direction.swipe((AppiumDriver) parent, this, 0, 0, 0, 0, duration); + direction.swipe((AppiumDriver) parent, this, 0, 0, duration); + } + + @Override + public void swipe(SwipeElementDirection direction, int offset1, + int offset2, int duration) throws IllegalCoordinatesException { + direction.swipe((AppiumDriver) parent, this, offset1, offset2, duration); } } diff --git a/src/main/java/io/appium/java_client/SwipeElementDirection.java b/src/main/java/io/appium/java_client/SwipeElementDirection.java index 06a9f867f..063605d8c 100644 --- a/src/main/java/io/appium/java_client/SwipeElementDirection.java +++ b/src/main/java/io/appium/java_client/SwipeElementDirection.java @@ -9,59 +9,181 @@ public enum SwipeElementDirection { */ UP{ @Override - void swipe(AppiumDriver driver, MobileElement element, - int xOffsetStart, int xOffsetEnd, int yOffsetStart, - int yOffsetEnd, int duration) throws IllegalCoordinatesException { - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(p.getX(), location.getY() + size.getHeight(), p.getX(), location.getY(), duration); + int getStartX(Point center, Point location, Dimension size, int ignored) { + return center.getX(); + } + + @Override + int getStartY(Point center, Point location, Dimension size, int offSet) { + int result = location.getY() + size.getHeight() - offSet; + checkYCoordinate(result, location, size, offSet); + return result; + } + + @Override + int getEndX(Point center, Point location, Dimension size, int ignored) { + return center.getX(); + } + + @Override + int getEndY(Point center, Point location, Dimension size, int offSet) { + int result = location.getY() + offSet; + checkYCoordinate(result, location, size, offSet); + return result; + } + + @Override + void checkDirection(int x1, int y1, int x2, int y2) { + if (y1 < y2) + throw new IllegalCoordinatesException("Y1 " + y1 + " and Y2 " + y2 + " are inconsistent. It looks like you are " + + "trying to perform the swiping down"); } }, /** * Down from the center of the upper */ DOWN{ + @Override - void swipe(AppiumDriver driver, MobileElement element, - int xOffsetStart, int xOffsetEnd, int yOffsetStart, - int yOffsetEnd, int duration) throws IllegalCoordinatesException { - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(p.getX(), location.getY(), p.getX(), location.getY() + size.getHeight(), duration); + int getStartX(Point center, Point location, Dimension size, int offSet) { + return center.getX(); + } + + @Override + int getStartY(Point center, Point location, Dimension size, int offSet) { + return UP.getEndY(center, location, size, offSet); + } + + @Override + int getEndX(Point center, Point location, Dimension size, int offSet) { + return center.getX(); + } + + @Override + int getEndY(Point center, Point location, Dimension size, int offSet) { + return UP.getStartY(center, location, size, offSet); + } + + @Override + void checkDirection(int x1, int y1, int x2, int y2) { + if (y1 > y2) + throw new IllegalCoordinatesException("Y1 " + y1 + " and Y2 " + y2 + " are inconsistent. It looks like you are " + + "trying to perform the swiping up"); } }, /** * To the left from the center of the rightmost */ LEFT{ + @Override - void swipe(AppiumDriver driver, MobileElement element, - int xOffsetStart, int xOffsetEnd, int yOffsetStart, - int yOffsetEnd, int duration) throws IllegalCoordinatesException { - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(location.getX() + size.getWidth(), p.getY(), location.getX(), p.getY(), duration); + int getStartX(Point center, Point location, Dimension size, int offSet) { + int result = location.getX() + size.getWidth() - offSet; + checkXCoordinate(result, location, size, offSet); + return result; } + + @Override + int getStartY(Point center, Point location, Dimension size, int offSet) { + return center.getY(); + } + + @Override + int getEndX(Point center, Point location, Dimension size, int offSet) { + int result = location.getX() + offSet; + checkXCoordinate(result, location, size, offSet); + return result; + } + + @Override + int getEndY(Point center, Point location, Dimension size, int offSet) { + return center.getY(); + } + + @Override + void checkDirection(int x1, int y1, int x2, int y2) { + if (x1 < x2) + throw new IllegalCoordinatesException("X1 " + x1 + " and X2 " + x2 + " are inconsistent. It looks like you are " + + "trying to perform the swiping right"); + + } }, /** * To the right from the center of the leftmost */ RIGHT{ + + @Override + int getStartX(Point center, Point location, Dimension size, int offSet) { + return LEFT.getEndX(center, location, size, offSet); + } + + @Override + int getStartY(Point center, Point location, Dimension size, int offSet) { + return center.getY(); + } + + @Override + int getEndX(Point center, Point location, Dimension size, int offSet) { + return LEFT.getStartX(center, location, size, offSet); + } + @Override - void swipe(AppiumDriver driver, MobileElement element, - int xOffsetStart, int xOffsetEnd, int yOffsetStart, - int yOffsetEnd, int duration) throws IllegalCoordinatesException { - Point p = element.getCenter(); - Point location = element.getLocation(); - Dimension size = element.getSize(); - driver.swipe(location.getX(), p.getY(), location.getX()+ size.getWidth(), p.getY(), duration); + int getEndY(Point center, Point location, Dimension size, int offSet) { + return center.getY(); + } + + @Override + void checkDirection(int x1, int y1, int x2, int y2) { + if (x1 > x2) + throw new IllegalCoordinatesException("X1 " + x1 + " and X2 " + x2 + " are inconsistent. It looks like you are " + + "trying to perform the swiping left"); } }; - abstract void swipe(AppiumDriver driver, MobileElement element, - int xOffsetStart, int xOffsetEnd, int yOffsetStart, - int yOffsetEnd, int duration) throws IllegalCoordinatesException; + abstract int getStartX(Point center, Point location, Dimension size, int offSet); + abstract int getStartY(Point center, Point location, Dimension size, int offSet); + abstract int getEndX(Point center, Point location, Dimension size, int offSet); + abstract int getEndY(Point center, Point location, Dimension size, int offSet); + abstract void checkDirection(int x1, int y1, int x2, int y2); + + void swipe(AppiumDriver driver, MobileElement element, + int offset1, int offset2, int duration) throws IllegalCoordinatesException{ + Point p = element.getCenter(); + Point location = element.getLocation(); + Dimension size = element.getSize(); + int startX = getStartX(p, location, size, offset1); + int startY = getStartY(p, location, size, offset1); + int endX = getEndX(p, location, size, offset2); + int endY = getEndY(p, location, size, offset2); + checkDirection(startX, startY, endX, endY); + + driver.swipe(startX, startY, endX, endY, duration); + } + + static void checkYCoordinate(int y, Point location, Dimension size, int offSet) + throws IllegalCoordinatesException { + int bottom = location.getY() + size.getHeight(); + int top = location.getY(); + if (y > bottom) + throw new IllegalCoordinatesException("The result Y " + y + " is lower than target element bottom " + + bottom); + if (y < top) + throw new IllegalCoordinatesException("The result Y " + y + " is higher than target element top " + + top); + + } + + static void checkXCoordinate(int x, Point location, Dimension size, int offSet) + throws IllegalCoordinatesException { + int right = location.getX() + size.getWidth(); + int left = location.getX(); + if (x > right) + throw new IllegalCoordinatesException("The result X " + x + " is righter than target element right border " + + right); + if (x < left) + throw new IllegalCoordinatesException("The result X " + x + " is lefter than target element left border " + + left); + + } } diff --git a/src/main/java/io/appium/java_client/TouchableElement.java b/src/main/java/io/appium/java_client/TouchableElement.java index 1f04e58dd..fa8f38702 100644 --- a/src/main/java/io/appium/java_client/TouchableElement.java +++ b/src/main/java/io/appium/java_client/TouchableElement.java @@ -1,52 +1,76 @@ -package io.appium.java_client; - -import org.openqa.selenium.WebElement; - -/** - * It supposed that mobile elements could be tappable, swipeable, zoomable and so on. - * This interface extends {@link WebElement} and describes this behavior. - */ -public interface TouchableElement extends WebElement { - - /** - * Convenience method for pinching the given element. - * "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. - * NOTE: - * This convenience method places the initial touches around the element, if this would happen to place one of them - * off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api - * instead of this method. - * - */ - public void pinch(); - - /** - * Convenience method for tapping the center of the given element - * - * @param fingers - * number of fingers/appendages to tap with - * @param duration - * how long between pressing down, and lifting fingers/appendages - */ - public void tap(int fingers, int duration); - - /** - * Convenience method for "zooming in" on the given element. - * "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. - * NOTE: - * This convenience method slides touches away from the element, if this would happen to place one of them - * off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api - * instead of this method. - */ - public void zoom(); - - /** - * Convenience method for swiping on the given element to the given direction - * - * @param direction UP, DOWN, LEFT, RIGHT - * - * @param duration amount of time in milliseconds for the entire swipe action to - * take - */ - public void swipe(SwipeElementDirection direction, int duration); - -} +package io.appium.java_client; + +import org.openqa.selenium.WebElement; + +/** + * It supposed that mobile elements could be tappable, swipeable, zoomable and so on. + * This interface extends {@link WebElement} and describes this behavior. + */ +public interface TouchableElement extends WebElement { + + /** + * Convenience method for pinching the given element. + * "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. + * NOTE: + * This convenience method places the initial touches around the element, if this would happen to place one of them + * off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api + * instead of this method. + * + */ + public void pinch(); + + /** + * Convenience method for tapping the center of the given element + * + * @param fingers + * number of fingers/appendages to tap with + * @param duration + * how long between pressing down, and lifting fingers/appendages + */ + public void tap(int fingers, int duration); + + /** + * Convenience method for "zooming in" on the given element. + * "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. + * NOTE: + * This convenience method slides touches away from the element, if this would happen to place one of them + * off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api + * instead of this method. + */ + public void zoom(); + + /** + * Convenience method for swiping on the given element to the given direction + * + * @param direction UP, DOWN, LEFT, RIGHT + * + * @param duration amount of time in milliseconds for the entire swipe action to + * take + */ + public void swipe(SwipeElementDirection direction, int duration); + + + /** + * Convenience method for swiping on the given element to the given direction + * + * @param direction direction UP, DOWN, LEFT, RIGHT + * + * @param offset1 is the offset from the border of the element. If direction is UP then + * this is offset from the bottom of the element. If direction is DOWN then + * this is offset from the top of the element. If direction is RIGHT then + * this is offset from the left border of the element. If direction is LEFT then + * this is offset from the right border of the element. + * + * @param offset2 is the offset from the border of the element. If direction is UP then + * this is offset from the top of the element. If direction is DOWN then + * this is offset from the bottom of the element. If direction is RIGHT then + * this is offset from the right border of the element. If direction is LEFT then + * this is offset from the left border of the element. + * + * @param duration amount of time in milliseconds for the entire swipe action to + * take + * @throws IllegalCoordinatesException when resulted coordinates are out of the element borders + * or disagree with the given direction + */ + public void swipe(SwipeElementDirection direction, int offset1, int offset2, int duration) throws IllegalCoordinatesException; +} diff --git a/src/test/java/io/appium/java_client/android/AndroidGestureTest.java b/src/test/java/io/appium/java_client/android/AndroidGestureTest.java index 459d74a4e..12cd0f341 100644 --- a/src/test/java/io/appium/java_client/android/AndroidGestureTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidGestureTest.java @@ -1,117 +1,138 @@ -/* - +Copyright 2014 Appium contributors - +Copyright 2014 Software Freedom Conservancy - + - +Licensed under the Apache License, Version 2.0 (the "License"); - +you may not use this file except in compliance with the License. - +You may obtain a copy of the License at - + - + http://www.apache.org/licenses/LICENSE-2.0 - + - +Unless required by applicable law or agreed to in writing, software - +distributed under the License is distributed on an "AS IS" BASIS, - +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +See the License for the specific language governing permissions and - +limitations under the License. - + */ - -package io.appium.java_client.android; - -import io.appium.java_client.*; -import io.appium.java_client.remote.MobileCapabilityType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.DesiredCapabilities; - -import java.io.File; -import java.net.URL; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -/** - * Test Mobile Driver features - */ -public class AndroidGestureTest { - private AndroidDriver driver; - - @Before - public void setup() throws Exception { - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "ApiDemos-debug.apk"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); - } - - @After - public void tearDown() throws Exception { - driver.quit(); - } - - @Test - public void MultiGestureSingleActionTest() throws InterruptedException { - //the underlying java library for Appium doesn't like multi-gestures with only a single action. - //but java-client should handle it, silently falling back to just performing a single action. - - MultiTouchAction multiTouch = new MultiTouchAction(driver); - TouchAction action0 = new TouchAction(driver).tap(100,300); - multiTouch.add(action0).perform(); - } - - @Test - public void dragNDropTest() { - - driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().description(\"Views\"))"); - driver.findElementByAccessibilityId("Views").click(); - - driver.findElement(MobileBy.AndroidUIAutomator("description(\"Drag and Drop\")")).click(); - WebElement actionBarTitle = driver.findElement(By.id("android:id/action_bar_title")); - - assertEquals("Wrong title.", "Views/Drag and Drop", actionBarTitle.getText()); - WebElement dragDot1 = driver.findElement(By.id("com.example.android.apis:id/drag_dot_1")); - WebElement dragDot3 = driver.findElement(By.id("com.example.android.apis:id/drag_dot_3")); - - WebElement dragText = driver.findElement(By.id("com.example.android.apis:id/drag_text")); - assertEquals("Drag text not empty", "", dragText.getText()); - - TouchAction dragNDrop = new TouchAction(driver).longPress(dragDot1).moveTo(dragDot3).release(); - dragNDrop.perform(); - - assertNotEquals("Drag text empty", "", dragText.getText()); - } - - @Test - public void TapSingleFingerTest() throws InterruptedException { - Thread.sleep(2500); - driver.tap(1,200,300,1000); - } - - @Test - public void elementGestureTest(){ - driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); - MobileElement e = (MobileElement) driver.findElement(MobileBy.AccessibilityId("App")); - e.tap(1, 1500); - System.out.println("tap"); - MobileElement e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); - e2.zoom(); - System.out.println("zoom"); - e2.swipe(SwipeElementDirection.RIGHT,1000); - System.out.println("RIGHT"); - driver.sendKeyEvent(AndroidKeyCode.BACK); - e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); - e2.swipe(SwipeElementDirection.LEFT, 1000); - System.out.println("LEFT"); - e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); - e2.swipe(SwipeElementDirection.DOWN,1000); - System.out.println("DOWN"); - e2.swipe(SwipeElementDirection.UP,1000); - System.out.println("UP"); - } -} +/* + +Copyright 2014 Appium contributors + +Copyright 2014 Software Freedom Conservancy + + + +Licensed under the Apache License, Version 2.0 (the "License"); + +you may not use this file except in compliance with the License. + +You may obtain a copy of the License at + + + + http://www.apache.org/licenses/LICENSE-2.0 + + + +Unless required by applicable law or agreed to in writing, software + +distributed under the License is distributed on an "AS IS" BASIS, + +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +See the License for the specific language governing permissions and + +limitations under the License. + + */ + +package io.appium.java_client.android; + +import io.appium.java_client.*; +import io.appium.java_client.remote.MobileCapabilityType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.io.File; +import java.net.URL; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +/** + * Test Mobile Driver features + */ +public class AndroidGestureTest { + private AndroidDriver driver; + + @Before + public void setup() throws Exception { + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "ApiDemos-debug.apk"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); + } + + @After + public void tearDown() throws Exception { + driver.quit(); + } + + @Test + public void MultiGestureSingleActionTest() throws InterruptedException { + //the underlying java library for Appium doesn't like multi-gestures with only a single action. + //but java-client should handle it, silently falling back to just performing a single action. + + MultiTouchAction multiTouch = new MultiTouchAction(driver); + TouchAction action0 = new TouchAction(driver).tap(100,300); + multiTouch.add(action0).perform(); + } + + @Test + public void dragNDropTest() { + + driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().description(\"Views\"))"); + driver.findElementByAccessibilityId("Views").click(); + + driver.findElement(MobileBy.AndroidUIAutomator("description(\"Drag and Drop\")")).click(); + WebElement actionBarTitle = driver.findElement(By.id("android:id/action_bar_title")); + + assertEquals("Wrong title.", "Views/Drag and Drop", actionBarTitle.getText()); + WebElement dragDot1 = driver.findElement(By.id("com.example.android.apis:id/drag_dot_1")); + WebElement dragDot3 = driver.findElement(By.id("com.example.android.apis:id/drag_dot_3")); + + WebElement dragText = driver.findElement(By.id("com.example.android.apis:id/drag_text")); + assertEquals("Drag text not empty", "", dragText.getText()); + + TouchAction dragNDrop = new TouchAction(driver).longPress(dragDot1).moveTo(dragDot3).release(); + dragNDrop.perform(); + + assertNotEquals("Drag text empty", "", dragText.getText()); + } + + @Test + public void TapSingleFingerTest() throws InterruptedException { + Thread.sleep(2500); + driver.tap(1,200,300,1000); + } + + @Test + public void elementGestureTest(){ + driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); + MobileElement e = (MobileElement) driver.findElement(MobileBy.AccessibilityId("App")); + e.tap(1, 1500); + System.out.println("tap"); + MobileElement e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.zoom(); + System.out.println("zoom"); + e2.swipe(SwipeElementDirection.RIGHT,1000); + System.out.println("RIGHT"); + + e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.swipe(SwipeElementDirection.RIGHT, 10, 20, 1000); + System.out.println("RIGHT Left border + 10 Right border - 20"); + + e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.swipe(SwipeElementDirection.LEFT, 1000); + System.out.println("LEFT"); + + e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.swipe(SwipeElementDirection.LEFT, 10, 20, 1000); + System.out.println("LEFT Right border - 10 Left border + 20"); + + driver.sendKeyEvent(AndroidKeyCode.BACK); + e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.swipe(SwipeElementDirection.DOWN,1000); + System.out.println("DOWN"); + + e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.swipe(SwipeElementDirection.DOWN, 10, 20, 1000); + System.out.println("DOWN Top - 10 Bottom + 20"); + + e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.swipe(SwipeElementDirection.UP,1000); + System.out.println("UP"); + + e2 = (MobileElement) driver.findElementByClassName("android.widget.TextView"); + e2.swipe(SwipeElementDirection.UP, 10, 20, 1000); + System.out.println("UP Bottom + 10 Top - 20"); + + } +} diff --git a/src/test/java/io/appium/java_client/ios/iOSGestureTest.java b/src/test/java/io/appium/java_client/ios/iOSGestureTest.java index eddb5eb6c..0a381e291 100644 --- a/src/test/java/io/appium/java_client/ios/iOSGestureTest.java +++ b/src/test/java/io/appium/java_client/ios/iOSGestureTest.java @@ -1,145 +1,149 @@ -/* - +Copyright 2014 Appium contributors - +Copyright 2014 Software Freedom Conservancy - + - +Licensed under the Apache License, Version 2.0 (the "License"); - +you may not use this file except in compliance with the License. - +You may obtain a copy of the License at - + - + http://www.apache.org/licenses/LICENSE-2.0 - + - +Unless required by applicable law or agreed to in writing, software - +distributed under the License is distributed on an "AS IS" BASIS, - +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +See the License for the specific language governing permissions and - +limitations under the License. - + */ - -package io.appium.java_client.ios; - -import io.appium.java_client.AppiumDriver; -import io.appium.java_client.MobileElement; -import io.appium.java_client.MultiTouchAction; -import io.appium.java_client.SwipeElementDirection; -import io.appium.java_client.TouchAction; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.remote.MobileCapabilityType; - -import java.io.File; -import java.net.URL; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.Alert; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -/** - * Test Mobile Driver features - */ -public class iOSGestureTest { - - private AppiumDriver driver; - - @Before - public void setup() throws Exception { - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "TestApp.app.zip"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); - } - - @After - public void tearDown() throws Exception { - driver.quit(); - } - - @Test - public void TouchActionTest() throws InterruptedException { - WebElement button = driver.findElementsByClassName("UIAButton").get(3); - TouchAction action = new TouchAction(driver); - action.press(button).perform(); - Thread.sleep(2000); - } - - @Test - public void TouchActionChainTest() throws InterruptedException { - WebDriverWait wait = new WebDriverWait(driver, 2); - - WebElement button = driver.findElementsByClassName("UIAButton").get(5); - TouchAction action = new TouchAction(driver); - action.press(button).perform(); - - wait.until(ExpectedConditions.alertIsPresent()); - Alert alert = driver.switchTo().alert(); - alert.accept(); - - WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]"); - action = new TouchAction(driver); - action.press(mapview).moveTo(mapview, 0, 100).release().perform(); - Thread.sleep(2000); - } - - @Test - public void MultiGestureTest() throws InterruptedException { - WebDriverWait wait = new WebDriverWait(driver, 2); - - WebElement button = driver.findElementsByClassName("UIAButton").get(5); - TouchAction action = new TouchAction(driver); - action.press(button).perform(); - - wait.until(ExpectedConditions.alertIsPresent()); - Alert alert = driver.switchTo().alert(); - alert.accept(); - - WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]"); - - MultiTouchAction multiTouch = new MultiTouchAction(driver); - TouchAction action0 = new TouchAction(driver).press(mapview, 100, 0).moveTo(mapview, 0,-80).release(); - TouchAction action1 = new TouchAction(driver).press(mapview, 100, 50).moveTo(mapview, 0,80).release(); - multiTouch.add(action0).add(action1).perform(); - Thread.sleep(2000); - } - - @Test - public void ZoomTest() throws InterruptedException { - WebDriverWait wait = new WebDriverWait(driver, 2); - - WebElement button = driver.findElementsByClassName("UIAButton").get(5); - TouchAction action = new TouchAction(driver); - action.press(button).perform(); - - wait.until(ExpectedConditions.alertIsPresent()); - Alert alert = driver.switchTo().alert(); - alert.accept(); - - WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]"); - - driver.zoom(mapview); - Thread.sleep(2000); - } - - @Test - public void TapSingleFingerTest() { - driver.tap(1,100,200,1000); - } - - @Test - public void elementGestureTest(){ - MobileElement e = (MobileElement) driver.findElementByName("TextField1"); - e.tap(1, 1500); - e.zoom(); - e.pinch(); - e.swipe(SwipeElementDirection.UP,2000); - e.swipe(SwipeElementDirection.DOWN,2000); - e.swipe(SwipeElementDirection.LEFT,2000); - e.swipe(SwipeElementDirection.RIGHT,2000); - } -} +/* + +Copyright 2014 Appium contributors + +Copyright 2014 Software Freedom Conservancy + + + +Licensed under the Apache License, Version 2.0 (the "License"); + +you may not use this file except in compliance with the License. + +You may obtain a copy of the License at + + + + http://www.apache.org/licenses/LICENSE-2.0 + + + +Unless required by applicable law or agreed to in writing, software + +distributed under the License is distributed on an "AS IS" BASIS, + +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +See the License for the specific language governing permissions and + +limitations under the License. + + */ + +package io.appium.java_client.ios; + +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.MobileElement; +import io.appium.java_client.MultiTouchAction; +import io.appium.java_client.SwipeElementDirection; +import io.appium.java_client.TouchAction; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.remote.MobileCapabilityType; + +import java.io.File; +import java.net.URL; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Alert; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** + * Test Mobile Driver features + */ +public class iOSGestureTest { + + private AppiumDriver driver; + + @Before + public void setup() throws Exception { + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "TestApp.app.zip"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1"); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); + } + + @After + public void tearDown() throws Exception { + driver.quit(); + } + + @Test + public void TouchActionTest() throws InterruptedException { + WebElement button = driver.findElementsByClassName("UIAButton").get(3); + TouchAction action = new TouchAction(driver); + action.press(button).perform(); + Thread.sleep(2000); + } + + @Test + public void TouchActionChainTest() throws InterruptedException { + WebDriverWait wait = new WebDriverWait(driver, 2); + + WebElement button = driver.findElementsByClassName("UIAButton").get(5); + TouchAction action = new TouchAction(driver); + action.press(button).perform(); + + wait.until(ExpectedConditions.alertIsPresent()); + Alert alert = driver.switchTo().alert(); + alert.accept(); + + WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]"); + action = new TouchAction(driver); + action.press(mapview).moveTo(mapview, 0, 100).release().perform(); + Thread.sleep(2000); + } + + @Test + public void MultiGestureTest() throws InterruptedException { + WebDriverWait wait = new WebDriverWait(driver, 2); + + WebElement button = driver.findElementsByClassName("UIAButton").get(5); + TouchAction action = new TouchAction(driver); + action.press(button).perform(); + + wait.until(ExpectedConditions.alertIsPresent()); + Alert alert = driver.switchTo().alert(); + alert.accept(); + + WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]"); + + MultiTouchAction multiTouch = new MultiTouchAction(driver); + TouchAction action0 = new TouchAction(driver).press(mapview, 100, 0).moveTo(mapview, 0,-80).release(); + TouchAction action1 = new TouchAction(driver).press(mapview, 100, 50).moveTo(mapview, 0,80).release(); + multiTouch.add(action0).add(action1).perform(); + Thread.sleep(2000); + } + + @Test + public void ZoomTest() throws InterruptedException { + WebDriverWait wait = new WebDriverWait(driver, 2); + + WebElement button = driver.findElementsByClassName("UIAButton").get(5); + TouchAction action = new TouchAction(driver); + action.press(button).perform(); + + wait.until(ExpectedConditions.alertIsPresent()); + Alert alert = driver.switchTo().alert(); + alert.accept(); + + WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]"); + + driver.zoom(mapview); + Thread.sleep(2000); + } + + @Test + public void TapSingleFingerTest() { + driver.tap(1,100,200,1000); + } + + @Test + public void elementGestureTest(){ + MobileElement e = (MobileElement) driver.findElementByName("TextField1"); + e.tap(1, 1500); + e.zoom(); + e.pinch(); + e.swipe(SwipeElementDirection.UP,2000); + e.swipe(SwipeElementDirection.UP, 5, 5, 2000); + e.swipe(SwipeElementDirection.DOWN,2000); + e.swipe(SwipeElementDirection.DOWN, 5, 5, 2000); + e.swipe(SwipeElementDirection.LEFT,2000); + e.swipe(SwipeElementDirection.LEFT, 5, 5, 2000); + e.swipe(SwipeElementDirection.RIGHT,2000); + e.swipe(SwipeElementDirection.RIGHT, 5, 5, 2000); + } +} From 3a076435ec4f26504b7053517dabe7063edc23e0 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Wed, 11 Mar 2015 01:17:37 +0400 Subject: [PATCH 3/3] #160 fixed parameter names and comments. --- .../io/appium/java_client/MobileElement.java | 163 +++++++++--------- .../appium/java_client/TouchableElement.java | 155 +++++++++-------- 2 files changed, 161 insertions(+), 157 deletions(-) diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index e4d8b526e..02f18722e 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -1,81 +1,82 @@ -/* - +Copyright 2014 Appium contributors - +Copyright 2014 Software Freedom Conservancy - + - +Licensed under the Apache License, Version 2.0 (the "License"); - +you may not use this file except in compliance with the License. - +You may obtain a copy of the License at - + - + http://www.apache.org/licenses/LICENSE-2.0 - + - +Unless required by applicable law or agreed to in writing, software - +distributed under the License is distributed on an "AS IS" BASIS, - +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +See the License for the specific language governing permissions and - +limitations under the License. - + */ - -package io.appium.java_client; - -import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.FileDetector; -import org.openqa.selenium.remote.RemoteWebElement; - -import java.util.List; - -public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, TouchableElement { - - protected FileDetector fileDetector; - - public List findElements(By by) { - return by.findElements(this); - } - - public WebElement findElement(By by) { - return by.findElement(this); - } - - public WebElement findElementByAccessibilityId(String using) { - return findElement("accessibility id", using); - } - - public List findElementsByAccessibilityId(String using) { - return findElements("accessibility id", using); - } - - public Point getCenter() { - Point upperLeft = this.getLocation(); - Dimension dimensions = this.getSize(); - return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); - } - - @Override - public void pinch() { - ((AppiumDriver) parent).pinch(this); - } - - @Override - public void tap(int fingers, int duration) { - ((AppiumDriver) parent).tap(fingers, this, duration); - } - - @Override - public void zoom() { - ((AppiumDriver) parent).zoom(this); - } - - - @Override - public void swipe(SwipeElementDirection direction, int duration) { - direction.swipe((AppiumDriver) parent, this, 0, 0, duration); - } - - @Override - public void swipe(SwipeElementDirection direction, int offset1, - int offset2, int duration) throws IllegalCoordinatesException { - direction.swipe((AppiumDriver) parent, this, offset1, offset2, duration); - } -} +/* + +Copyright 2014 Appium contributors + +Copyright 2014 Software Freedom Conservancy + + + +Licensed under the Apache License, Version 2.0 (the "License"); + +you may not use this file except in compliance with the License. + +You may obtain a copy of the License at + + + + http://www.apache.org/licenses/LICENSE-2.0 + + + +Unless required by applicable law or agreed to in writing, software + +distributed under the License is distributed on an "AS IS" BASIS, + +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +See the License for the specific language governing permissions and + +limitations under the License. + + */ + +package io.appium.java_client; + +import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.FileDetector; +import org.openqa.selenium.remote.RemoteWebElement; + +import java.util.List; + +public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, TouchableElement { + + protected FileDetector fileDetector; + + public List findElements(By by) { + return by.findElements(this); + } + + public WebElement findElement(By by) { + return by.findElement(this); + } + + public WebElement findElementByAccessibilityId(String using) { + return findElement("accessibility id", using); + } + + public List findElementsByAccessibilityId(String using) { + return findElements("accessibility id", using); + } + + public Point getCenter() { + Point upperLeft = this.getLocation(); + Dimension dimensions = this.getSize(); + return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); + } + + @Override + public void pinch() { + ((AppiumDriver) parent).pinch(this); + } + + @Override + public void tap(int fingers, int duration) { + ((AppiumDriver) parent).tap(fingers, this, duration); + } + + @Override + public void zoom() { + ((AppiumDriver) parent).zoom(this); + } + + + @Override + public void swipe(SwipeElementDirection direction, int duration) { + direction.swipe((AppiumDriver) parent, this, 0, 0, duration); + } + + @Override + public void swipe(SwipeElementDirection direction, int offsetFromStartBorder, + int offsetFromEndBorder, int duration) throws IllegalCoordinatesException { + direction.swipe((AppiumDriver) parent, this, offsetFromStartBorder, + offsetFromEndBorder, duration); + } +} diff --git a/src/main/java/io/appium/java_client/TouchableElement.java b/src/main/java/io/appium/java_client/TouchableElement.java index fa8f38702..c92c3e0f9 100644 --- a/src/main/java/io/appium/java_client/TouchableElement.java +++ b/src/main/java/io/appium/java_client/TouchableElement.java @@ -1,76 +1,79 @@ -package io.appium.java_client; - -import org.openqa.selenium.WebElement; - -/** - * It supposed that mobile elements could be tappable, swipeable, zoomable and so on. - * This interface extends {@link WebElement} and describes this behavior. - */ -public interface TouchableElement extends WebElement { - - /** - * Convenience method for pinching the given element. - * "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. - * NOTE: - * This convenience method places the initial touches around the element, if this would happen to place one of them - * off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api - * instead of this method. - * - */ - public void pinch(); - - /** - * Convenience method for tapping the center of the given element - * - * @param fingers - * number of fingers/appendages to tap with - * @param duration - * how long between pressing down, and lifting fingers/appendages - */ - public void tap(int fingers, int duration); - - /** - * Convenience method for "zooming in" on the given element. - * "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. - * NOTE: - * This convenience method slides touches away from the element, if this would happen to place one of them - * off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api - * instead of this method. - */ - public void zoom(); - - /** - * Convenience method for swiping on the given element to the given direction - * - * @param direction UP, DOWN, LEFT, RIGHT - * - * @param duration amount of time in milliseconds for the entire swipe action to - * take - */ - public void swipe(SwipeElementDirection direction, int duration); - - - /** - * Convenience method for swiping on the given element to the given direction - * - * @param direction direction UP, DOWN, LEFT, RIGHT - * - * @param offset1 is the offset from the border of the element. If direction is UP then - * this is offset from the bottom of the element. If direction is DOWN then - * this is offset from the top of the element. If direction is RIGHT then - * this is offset from the left border of the element. If direction is LEFT then - * this is offset from the right border of the element. - * - * @param offset2 is the offset from the border of the element. If direction is UP then - * this is offset from the top of the element. If direction is DOWN then - * this is offset from the bottom of the element. If direction is RIGHT then - * this is offset from the right border of the element. If direction is LEFT then - * this is offset from the left border of the element. - * - * @param duration amount of time in milliseconds for the entire swipe action to - * take - * @throws IllegalCoordinatesException when resulted coordinates are out of the element borders - * or disagree with the given direction - */ - public void swipe(SwipeElementDirection direction, int offset1, int offset2, int duration) throws IllegalCoordinatesException; -} +package io.appium.java_client; + +import org.openqa.selenium.WebElement; + +/** + * It supposed that mobile elements could be tappable, swipeable, zoomable and so on. + * This interface extends {@link WebElement} and describes this behavior. + */ +public interface TouchableElement extends WebElement { + + /** + * Convenience method for pinching the given element. + * "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. + * NOTE: + * This convenience method places the initial touches around the element, if this would happen to place one of them + * off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api + * instead of this method. + * + */ + public void pinch(); + + /** + * Convenience method for tapping the center of the given element + * + * @param fingers + * number of fingers/appendages to tap with + * @param duration + * how long between pressing down, and lifting fingers/appendages + */ + public void tap(int fingers, int duration); + + /** + * Convenience method for "zooming in" on the given element. + * "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. + * NOTE: + * This convenience method slides touches away from the element, if this would happen to place one of them + * off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api + * instead of this method. + */ + public void zoom(); + + /** + * Convenience method for swiping on the given element to the given direction + * + * @param direction UP, DOWN, LEFT, RIGHT + * + * @param duration amount of time in milliseconds for the entire swipe action to + * take + */ + public void swipe(SwipeElementDirection direction, int duration); + + + /** + * Convenience method for swiping on the given element to the given direction + * + * @param direction direction UP, DOWN, LEFT, RIGHT + * + * @param offsetFromEndBorder is the offset from the border of the element where the swiping should be started. + * If direction is UP then + * this is offset from the bottom of the element. If direction is DOWN then + * this is offset from the top of the element. If direction is RIGHT then + * this is offset from the left border of the element. If direction is LEFT then + * this is offset from the right border of the element. + * + * @param offsetFromEndBorder is the offset from the border of the element where the swiping should be finished. + * If direction is UP then + * this is offset from the top of the element. If direction is DOWN then + * this is offset from the bottom of the element. If direction is RIGHT then + * this is offset from the right border of the element. If direction is LEFT then + * this is offset from the left border of the element. + * + * @param duration amount of time in milliseconds for the entire swipe action to + * take + * @throws IllegalCoordinatesException when resulted coordinates are out of the element borders + * or disagree with the given direction + */ + public void swipe(SwipeElementDirection direction, int offsetFromStartBorder, + int offsetFromEndBorder, int duration) throws IllegalCoordinatesException; +}