From b6aa487c8ce6442a67354279fa38360bd2437cb7 Mon Sep 17 00:00:00 2001 From: SrinivasanSekar Date: Fri, 12 Aug 2016 00:13:55 +0530 Subject: [PATCH 01/20] Splitting of TouchActions --- .../io/appium/java_client/AppiumDriver.java | 128 ++---------------- .../io/appium/java_client/MobileDriver.java | 2 +- .../io/appium/java_client/MobileElement.java | 32 ++++- .../appium/java_client/MultiTouchAction.java | 88 ++++++++++++ .../io/appium/java_client/TouchAction.java | 4 +- .../io/appium/java_client/TouchShortcuts.java | 110 --------------- .../appium/java_client/TouchableElement.java | 94 ++++++++++++- .../java_client/android/AndroidDriver.java | 6 +- .../android/AndroidTouchAction.java | 22 +++ .../io/appium/java_client/ios/IOSDriver.java | 6 +- .../java_client/ios/IOSTouchAction.java | 24 ++++ 11 files changed, 279 insertions(+), 237 deletions(-) delete mode 100644 src/main/java/io/appium/java_client/TouchShortcuts.java create mode 100644 src/main/java/io/appium/java_client/android/AndroidTouchAction.java create mode 100644 src/main/java/io/appium/java_client/ios/IOSTouchAction.java diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index b41879151..8e4067b71 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -349,9 +349,9 @@ public void performMultiTouchAction( } /** - * @see TouchShortcuts#tap(int, WebElement, int). + * @see TouchableElement#tap(int, WebElement, int). */ - @Override public void tap(int fingers, WebElement element, int duration) { + public void tap(int fingers, WebElement element, int duration) { MultiTouchAction multiTouch = new MultiTouchAction(this); for (int i = 0; i < fingers; i++) { @@ -362,9 +362,9 @@ public void performMultiTouchAction( } /** - * @see TouchShortcuts#tap(int, int, int, int). + * @see TouchableElement#tap(int, int, int, int). */ - @Override public void tap(int fingers, int x, int y, int duration) { + public void tap(int fingers, int x, int y, int duration) { MultiTouchAction multiTouch = new MultiTouchAction(this); for (int i = 0; i < fingers; i++) { @@ -374,145 +374,45 @@ public void performMultiTouchAction( multiTouch.perform(); } - protected void doSwipe(int startx, int starty, int endx, int endy, int duration) { - TouchAction touchAction = new TouchAction(this); - - // appium converts press-wait-moveto-release to a swipe action - touchAction.press(startx, starty).waitAction(duration).moveTo(endx, endy).release(); - - touchAction.perform(); - } - /** - * @see TouchShortcuts#swipe(int, int, int, int, int). + * @see TouchableElement#swipe(int, int, int, int, int). */ - @Override public abstract void swipe(int startx, int starty, int endx, int endy, int duration); + public abstract void swipe(int startx, int starty, int endx, int endy, int duration); /** - * Convenience method for pinching an element on the screen. - * "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. - * - * @param el The element to pinch. + * @see TouchableElement#pinch(WebElement). */ public void pinch(WebElement el) { MultiTouchAction multiTouch = new MultiTouchAction(this); - Dimension dimensions = el.getSize(); - Point upperLeft = el.getLocation(); - Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, - upperLeft.getY() + dimensions.getHeight() / 2); - int yOffset = center.getY() - upperLeft.getY(); - - TouchAction action0 = - new TouchAction(this).press(el, center.getX(), center.getY() - yOffset).moveTo(el) - .release(); - TouchAction action1 = - new TouchAction(this).press(el, center.getX(), center.getY() + yOffset).moveTo(el) - .release(); - - multiTouch.add(action0).add(action1); - - multiTouch.perform(); + multiTouch.pinch(el).perform(); } /** - * Convenience method for pinching an element on the screen. - * "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 at a distance, - * 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. - * - * @param x x coordinate to terminate the pinch on. - * @param y y coordinate to terminate the pinch on. + * @see TouchableElement#pinch(int, int). */ public void pinch(int x, int y) { MultiTouchAction multiTouch = new MultiTouchAction(this); - int scrHeight = manage().window().getSize().getHeight(); - int yOffset = 100; - - if (y - 100 < 0) { - yOffset = y; - } else if (y + 100 > scrHeight) { - yOffset = scrHeight - y; - } - - TouchAction action0 = new TouchAction(this).press(x, y - yOffset).moveTo(x, y).release(); - TouchAction action1 = new TouchAction(this).press(x, y + yOffset).moveTo(x, y).release(); - - multiTouch.add(action0).add(action1); - - multiTouch.perform(); + multiTouch.pinch(x, y).perform(); } /** - * Convenience method for "zooming in" on an element on the screen. - * "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. - * - * @param el The element to pinch. + * @see TouchableElement#zoom(WebElement). */ public void zoom(WebElement el) { MultiTouchAction multiTouch = new MultiTouchAction(this); - Dimension dimensions = el.getSize(); - Point upperLeft = el.getLocation(); - Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, - upperLeft.getY() + dimensions.getHeight() / 2); - int yOffset = center.getY() - upperLeft.getY(); - - TouchAction action0 = new TouchAction(this).press(center.getX(), center.getY()) - .moveTo(el, center.getX(), center.getY() - yOffset).release(); - TouchAction action1 = new TouchAction(this).press(center.getX(), center.getY()) - .moveTo(el, center.getX(), center.getY() + yOffset).release(); - - multiTouch.add(action0).add(action1); - - multiTouch.perform(); + multiTouch.zoom(el).perform(); } /** - * Convenience method for "zooming in" on an element on the screen. - * "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. - * - * @param x x coordinate to start zoom on. - * @param y y coordinate to start zoom on. + * @see TouchableElement#zoom(int, int). */ public void zoom(int x, int y) { MultiTouchAction multiTouch = new MultiTouchAction(this); - int scrHeight = manage().window().getSize().getHeight(); - int yOffset = 100; - - if (y - 100 < 0) { - yOffset = y; - } else if (y + 100 > scrHeight) { - yOffset = scrHeight - y; - } - - TouchAction action0 = new TouchAction(this).press(x, y).moveTo(0, -yOffset).release(); - TouchAction action1 = new TouchAction(this).press(x, y).moveTo(0, yOffset).release(); - - multiTouch.add(action0).add(action1); - - multiTouch.perform(); + multiTouch.zoom(x, y).perform(); } /** diff --git a/src/main/java/io/appium/java_client/MobileDriver.java b/src/main/java/io/appium/java_client/MobileDriver.java index e6965aef9..19377583c 100644 --- a/src/main/java/io/appium/java_client/MobileDriver.java +++ b/src/main/java/io/appium/java_client/MobileDriver.java @@ -35,7 +35,7 @@ import java.util.Map; public interface MobileDriver extends WebDriver, PerformsTouchActions, ContextAware, Rotatable, - FindsByAccessibilityId, LocationContext, DeviceActionShortcuts, TouchShortcuts, + FindsByAccessibilityId, LocationContext, DeviceActionShortcuts, InteractsWithFiles, InteractsWithApps, HasAppStrings, FindsByClassName, FindsByCssSelector, FindsById, FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath { diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 958c409ed..05c3ab6fd 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -21,6 +21,7 @@ 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 java.util.List; @@ -42,18 +43,45 @@ public Point getCenter() { upperLeft.getY() + dimensions.getHeight() / 2); } + @Override public void tap(int fingers, int duration) { + ((AppiumDriver) parent).tap(fingers, this, duration); + } + + @Override public void tap(int fingers, int x, int y, int duration) { + ((AppiumDriver) parent).tap(fingers, x, y, duration); + } + + @Override public void tap(int fingers, WebElement element, int duration) { + ((AppiumDriver) parent).tap(fingers, element, duration); + } + @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 pinch(int x, int y) { + ((AppiumDriver) parent).pinch(x, y); + } + + @Override public void pinch(WebElement el) { + ((AppiumDriver) parent).pinch(el); } @Override public void zoom() { ((AppiumDriver) parent).zoom(this); } + @Override public void zoom(int x, int y) { + ((AppiumDriver) parent).zoom(x, y); + } + + @Override public void zoom(WebElement el) { + ((AppiumDriver) parent).zoom(el); + } + + @Override public void swipe(int startx, int starty, int endx, int endy, int duration) { + ((AppiumDriver) parent).swipe(startx, startx, endx, endy ,duration); + } @Override public void swipe(SwipeElementDirection direction, int duration) { direction.swipe((AppiumDriver) parent, this, 0, 0, duration); diff --git a/src/main/java/io/appium/java_client/MultiTouchAction.java b/src/main/java/io/appium/java_client/MultiTouchAction.java index 7bde2a05d..053a62307 100644 --- a/src/main/java/io/appium/java_client/MultiTouchAction.java +++ b/src/main/java/io/appium/java_client/MultiTouchAction.java @@ -20,6 +20,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; + /** * Used for Webdriver 3 multi-touch gestures * See the Webriver 3 spec https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html @@ -86,4 +90,88 @@ protected ImmutableMap getParameters() { } return ImmutableMap.of("actions", listOfActionChains.build()); } + + /** + * @see TouchableElement#pinch(WebElement). + */ + public MultiTouchAction pinch(WebElement el) { + MultiTouchAction multiTouch = new MultiTouchAction(driver); + + Dimension dimensions = el.getSize(); + Point upperLeft = el.getLocation(); + Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, + upperLeft.getY() + dimensions.getHeight() / 2); + int yOffset = center.getY() - upperLeft.getY(); + + TouchAction action0 = + new TouchAction(driver).press(el, center.getX(), center.getY() - yOffset).moveTo(el) + .release(); + TouchAction action1 = + new TouchAction(driver).press(el, center.getX(), center.getY() + yOffset).moveTo(el) + .release(); + + return multiTouch.add(action0).add(action1); + } + + /** + * @see TouchableElement#pinch(int, int). + */ + public MultiTouchAction pinch(int x, int y) { + MultiTouchAction multiTouch = new MultiTouchAction(driver); + + int scrHeight = driver.manage().window().getSize().getHeight(); + int yOffset = 100; + + if (y - 100 < 0) { + yOffset = y; + } else if (y + 100 > scrHeight) { + yOffset = scrHeight - y; + } + + TouchAction action0 = new TouchAction(driver).press(x, y - yOffset).moveTo(x, y).release(); + TouchAction action1 = new TouchAction(driver).press(x, y + yOffset).moveTo(x, y).release(); + + return multiTouch.add(action0).add(action1); + } + + /** + * @see TouchableElement#zoom(WebElement). + */ + public MultiTouchAction zoom(WebElement el) { + MultiTouchAction multiTouch = new MultiTouchAction(driver); + + Dimension dimensions = el.getSize(); + Point upperLeft = el.getLocation(); + Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, + upperLeft.getY() + dimensions.getHeight() / 2); + int yOffset = center.getY() - upperLeft.getY(); + + TouchAction action0 = new TouchAction(driver).press(center.getX(), center.getY()) + .moveTo(el, center.getX(), center.getY() - yOffset).release(); + TouchAction action1 = new TouchAction(driver).press(center.getX(), center.getY()) + .moveTo(el, center.getX(), center.getY() + yOffset).release(); + + return multiTouch.add(action0).add(action1); + } + + /** + * @see TouchableElement#zoom(int, int). + */ + public MultiTouchAction zoom(int x, int y) { + MultiTouchAction multiTouch = new MultiTouchAction(driver); + + int scrHeight = driver.manage().window().getSize().getHeight(); + int yOffset = 100; + + if (y - 100 < 0) { + yOffset = y; + } else if (y + 100 > scrHeight) { + yOffset = scrHeight - y; + } + + TouchAction action0 = new TouchAction(driver).press(x, y).moveTo(0, -yOffset).release(); + TouchAction action1 = new TouchAction(driver).press(x, y).moveTo(0, yOffset).release(); + + return multiTouch.add(action0).add(action1); + } } diff --git a/src/main/java/io/appium/java_client/TouchAction.java b/src/main/java/io/appium/java_client/TouchAction.java index 3d1ba66a2..c29e815e2 100644 --- a/src/main/java/io/appium/java_client/TouchAction.java +++ b/src/main/java/io/appium/java_client/TouchAction.java @@ -35,7 +35,7 @@ */ @SuppressWarnings({"rawtypes", "unchecked"}) public class TouchAction { - ImmutableList.Builder parameterBuilder; + protected ImmutableList.Builder parameterBuilder; private MobileDriver driver; public TouchAction(MobileDriver driver) { @@ -346,7 +346,7 @@ protected void clearParameters() { /** * Just holds values to eventually return the parameters required for the mjsonwp. */ - private class ActionParameter { + protected class ActionParameter { private String actionName; private ImmutableMap.Builder optionsBuilder; diff --git a/src/main/java/io/appium/java_client/TouchShortcuts.java b/src/main/java/io/appium/java_client/TouchShortcuts.java deleted file mode 100644 index ab8625ef2..000000000 --- a/src/main/java/io/appium/java_client/TouchShortcuts.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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.WebElement; - -public interface TouchShortcuts { - - /** - * Convenience method for "zooming in" on an element on the screen. - * "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. - * - * @param x x coordinate to start zoom on. - * @param y y coordinate to start zoom on. - */ - void zoom(int x, int y); - - /** - * Convenience method for "zooming in" on an element on the screen. - * "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. - * - * @param el The element to pinch. - */ - void zoom(WebElement el); - - /** - * Convenience method for tapping a position on the screen. - * - * @param fingers number of fingers/appendages to tap with. - * @param x x coordinate. - * @param y y coordinate. - * @param duration how long between pressing down, and lifting fingers/appendages. - */ - void tap(int fingers, int x, int y, int duration); - - /** - * Convenience method for tapping the center of an element on the screen. - * - * @param fingers number of fingers/appendages to tap with. - * @param element element to tap. - * @param duration how long between pressing down, and lifting fingers/appendages. - */ - void tap(int fingers, WebElement element, int duration); - - /** - * Convenience method for swiping across the screen. - * - * @param startx starting x coordinate. - * @param starty starting y coordinate. - * @param endx ending x coordinate. - * @param endy ending y coordinate. - * @param duration amount of time in milliseconds for the entire swipe action to take - */ - void swipe(int startx, int starty, int endx, int endy, int duration); - - /** - * Convenience method for pinching an element on the screen. - * "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 at a distance, - * 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. - * - * @param x x coordinate to terminate the pinch on. - * @param y y coordinate to terminate the pinch on. - */ - void pinch(int x, int y); - - /** - * Convenience method for pinching an element on the screen. - * "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. - * - * @param el The element to pinch. - */ - void pinch(WebElement el); - -} diff --git a/src/main/java/io/appium/java_client/TouchableElement.java b/src/main/java/io/appium/java_client/TouchableElement.java index 757c99626..e46a53fd0 100644 --- a/src/main/java/io/appium/java_client/TouchableElement.java +++ b/src/main/java/io/appium/java_client/TouchableElement.java @@ -72,6 +72,61 @@ public interface TouchableElement extends WebElement, Find List findElementsByXPath(String xPath); + /** + * 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. + */ + void tap(int fingers, int duration); + + /** + * Convenience method for tapping a position on the screen. + * + * @param fingers number of fingers/appendages to tap with. + * @param x x coordinate. + * @param y y coordinate. + * @param duration how long between pressing down, and lifting fingers/appendages. + */ + void tap(int fingers, int x, int y, int duration); + + /** + * Convenience method for tapping the center of an element on the screen. + * + * @param fingers number of fingers/appendages to tap with. + * @param element element to tap. + * @param duration how long between pressing down, and lifting fingers/appendages. + */ + void tap(int fingers, WebElement element, int duration); + + /** + * Convenience method for pinching an element on the screen. + * "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 at a distance, + * 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. + * + * @param x x coordinate to terminate the pinch on. + * @param y y coordinate to terminate the pinch on. + */ + void pinch(int x, int y); + + /** + * Convenience method for pinching an element on the screen. + * "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. + * + * @param el The element to pinch. + */ + void pinch(WebElement el); + /** * Convenience method for pinching the given element. * "pinching" refers to the action of two appendages pressing the screen @@ -85,12 +140,33 @@ public interface TouchableElement extends WebElement, Find void pinch(); /** - * Convenience method for tapping the center of the given element. + * Convenience method for "zooming in" on an element on the screen. + * "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. * - * @param fingers number of fingers/appendages to tap with. - * @param duration how long between pressing down, and lifting fingers/appendages. + * @param x x coordinate to start zoom on. + * @param y y coordinate to start zoom on. */ - void tap(int fingers, int duration); + void zoom(int x, int y); + + /** + * Convenience method for "zooming in" on an element on the screen. + * "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. + * + * @param el The element to pinch. + */ + void zoom(WebElement el); /** * Convenience method for "zooming in" on the given element. @@ -112,6 +188,16 @@ public interface TouchableElement extends WebElement, Find */ void swipe(SwipeElementDirection direction, int duration); + /** + * Convenience method for swiping across the screen. + * + * @param startx starting x coordinate. + * @param starty starting y coordinate. + * @param endx ending x coordinate. + * @param endy ending y coordinate. + * @param duration amount of time in milliseconds for the entire swipe action to take + */ + void swipe(int startx, int starty, int endx, int endy, int duration); /** * Convenience method for swiping on the given element to the given direction. diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 2ba445996..b104e7050 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -180,10 +180,12 @@ public AndroidDriver(Capabilities desiredCapabilities) { } /** - * @see io.appium.java_client.TouchShortcuts#swipe(int, int, int, int, int) + * @see io.appium.java_client.TouchableElement#swipe(int, int, int, int, int) */ @Override public void swipe(int startx, int starty, int endx, int endy, int duration) { - doSwipe(startx, starty, endx, endy, duration); + AndroidTouchAction touchaction = new AndroidTouchAction(this); + + touchaction.swipe(startx, starty, endx, endy, duration).perform(); } /** diff --git a/src/main/java/io/appium/java_client/android/AndroidTouchAction.java b/src/main/java/io/appium/java_client/android/AndroidTouchAction.java new file mode 100644 index 000000000..94134ee72 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/AndroidTouchAction.java @@ -0,0 +1,22 @@ +package io.appium.java_client.android; + +import io.appium.java_client.MobileDriver; +import io.appium.java_client.TouchAction; +import io.appium.java_client.TouchableElement; + +public class AndroidTouchAction extends TouchAction { + + public AndroidTouchAction(MobileDriver driver) { + super(driver); + } + + /** + * @see TouchableElement#swipe(int, int, int, int, int). + */ + @Deprecated protected TouchAction swipe(int startx, int starty, int endx, int endy, int duration) { + + // appium converts press-wait-moveto-release to a swipe action + return press(startx, starty).waitAction(duration).moveTo(endx, endy).release(); + + } +} diff --git a/src/main/java/io/appium/java_client/ios/IOSDriver.java b/src/main/java/io/appium/java_client/ios/IOSDriver.java index 3c8d839f8..0b4053bfd 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -165,10 +165,12 @@ public IOSDriver(Capabilities desiredCapabilities) { } /** - * @see io.appium.java_client.TouchShortcuts#swipe(int, int, int, int, int). + * @see io.appium.java_client.TouchableElement#swipe(int, int, int, int, int). */ @Override public void swipe(int startx, int starty, int endx, int endy, int duration) { - doSwipe(startx, starty, endx - startx, endy - starty, duration); + IOSTouchAction touchaction = new IOSTouchAction(this); + + touchaction.swipe(startx, starty, endx, endy, duration).perform(); } /** diff --git a/src/main/java/io/appium/java_client/ios/IOSTouchAction.java b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java new file mode 100644 index 000000000..fadc4a60c --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java @@ -0,0 +1,24 @@ +package io.appium.java_client.ios; + +import io.appium.java_client.MobileDriver; +import io.appium.java_client.TouchAction; +import io.appium.java_client.TouchableElement; + + +public class IOSTouchAction extends TouchAction { + + public IOSTouchAction(MobileDriver driver) { + super(driver); + } + + /** + * @see TouchableElement#swipe(int, int, int, int, int). + */ + @Deprecated protected TouchAction swipe(int startx, int starty, int endx, int endy, int duration) { + endx = endx - startx; + endy = endy - starty; + + // appium converts press-wait-moveto-release to a swipe action + return press(startx, starty).waitAction(duration).moveTo(endx, endy).release(); + } +} From d76bad8a5dd0d38b5cb01a642b97fbcc3d3b070d Mon Sep 17 00:00:00 2001 From: SrinivasanSekar Date: Fri, 12 Aug 2016 00:30:49 +0530 Subject: [PATCH 02/20] Codacy Fixes --- src/main/java/io/appium/java_client/ios/IOSTouchAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/appium/java_client/ios/IOSTouchAction.java b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java index fadc4a60c..dee46ae84 100644 --- a/src/main/java/io/appium/java_client/ios/IOSTouchAction.java +++ b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java @@ -15,10 +15,10 @@ public IOSTouchAction(MobileDriver driver) { * @see TouchableElement#swipe(int, int, int, int, int). */ @Deprecated protected TouchAction swipe(int startx, int starty, int endx, int endy, int duration) { - endx = endx - startx; - endy = endy - starty; + int endX = endx - startx; + int endY = endy - starty; // appium converts press-wait-moveto-release to a swipe action - return press(startx, starty).waitAction(duration).moveTo(endx, endy).release(); + return press(startx, starty).waitAction(duration).moveTo(endX, endY).release(); } } From ffbb4de55bb1e64852de6a98699b02e030aad345 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Sat, 5 Nov 2016 00:37:14 +0300 Subject: [PATCH 03/20] #456 FIX #454 FIX: API redesign. - new interfaces were added - deprecated API --- .../io/appium/java_client/AppiumDriver.java | 10 +-- .../java_client/DeviceActionShortcuts.java | 5 ++ .../io/appium/java_client/HasDeviceTime.java | 31 +++++++++ .../io/appium/java_client/HidesKeyboard.java | 29 +++++++++ .../java_client/HidesKeyboardWithKeyName.java | 35 +++++++++++ .../io/appium/java_client/MobileCommand.java | 61 ++++++++++++++++++ .../io/appium/java_client/MobileDriver.java | 2 +- .../io/appium/java_client/PressesKeyCode.java | 63 +++++++++++++++++++ .../android/AndroidDeviceActionShortcuts.java | 5 ++ .../java_client/android/AndroidDriver.java | 3 +- .../android/AndroidMobileCommandHelper.java | 34 +++------- .../ios/IOSDeviceActionShortcuts.java | 5 ++ .../io/appium/java_client/ios/IOSDriver.java | 3 +- .../appium/java_client/ios/ShakesDevice.java | 32 ++++++++++ 14 files changed, 285 insertions(+), 33 deletions(-) create mode 100644 src/main/java/io/appium/java_client/HasDeviceTime.java create mode 100644 src/main/java/io/appium/java_client/HidesKeyboard.java create mode 100644 src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java create mode 100644 src/main/java/io/appium/java_client/PressesKeyCode.java create mode 100644 src/main/java/io/appium/java_client/ios/ShakesDevice.java diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index f5b716285..bc6b3be66 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -67,7 +67,7 @@ * for each target mobile OS (still Android and iOS) */ @SuppressWarnings("unchecked") -public abstract class AppiumDriver +public class AppiumDriver extends DefaultGenericMobileDriver { private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true); @@ -235,14 +235,16 @@ public void tap(int fingers, int x, int y, int duration) { for (int i = 0; i < fingers; i++) { multiTouch.add(createTap(x, y, duration)); } - multiTouch.perform(); } + @Deprecated /** - * @see TouchableElement#swipe(int, int, int, int, int). + * This method is deprecated due to it was moved to {@link TouchAction#} */ - public abstract void swipe(int startx, int starty, int endx, int endy, int duration); + public void swipe(int startx, int starty, int endx, int endy, int duration) { + + } /** * @see TouchableElement#pinch(WebElement). diff --git a/src/main/java/io/appium/java_client/DeviceActionShortcuts.java b/src/main/java/io/appium/java_client/DeviceActionShortcuts.java index 2790bf045..4f819d489 100644 --- a/src/main/java/io/appium/java_client/DeviceActionShortcuts.java +++ b/src/main/java/io/appium/java_client/DeviceActionShortcuts.java @@ -21,6 +21,11 @@ import org.openqa.selenium.remote.Response; +@Deprecated +/** + * This interface is deprecated and won't be supported anymore. + * Please use {@link HasDeviceTime} and {@link HidesKeyboard} API instead. + */ public interface DeviceActionShortcuts extends ExecutesMethod { /** diff --git a/src/main/java/io/appium/java_client/HasDeviceTime.java b/src/main/java/io/appium/java_client/HasDeviceTime.java new file mode 100644 index 000000000..292c83189 --- /dev/null +++ b/src/main/java/io/appium/java_client/HasDeviceTime.java @@ -0,0 +1,31 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * 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 static io.appium.java_client.MobileCommand.GET_DEVICE_TIME; + +import org.openqa.selenium.remote.Response; + +public interface HasDeviceTime extends ExecutesMethod { + /* + Gets device date and time for both iOS(Supports only real device) and Android devices + */ + default String getDeviceTime() { + Response response = execute(GET_DEVICE_TIME); + return response.getValue().toString(); + } +} diff --git a/src/main/java/io/appium/java_client/HidesKeyboard.java b/src/main/java/io/appium/java_client/HidesKeyboard.java new file mode 100644 index 000000000..5f292b0ce --- /dev/null +++ b/src/main/java/io/appium/java_client/HidesKeyboard.java @@ -0,0 +1,29 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * 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 static io.appium.java_client.MobileCommand.HIDE_KEYBOARD; + +public interface HidesKeyboard extends ExecutesMethod { + + /** + * Hides the keyboard if it is showing. + */ + default void hideKeyboard() { + execute(HIDE_KEYBOARD); + } +} diff --git a/src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java b/src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java new file mode 100644 index 000000000..011d4e0f5 --- /dev/null +++ b/src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java @@ -0,0 +1,35 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * 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 static io.appium.java_client.ios.IOSMobileCommandHelper.hideKeyboardCommand; + +public interface HidesKeyboardWithKeyName extends HidesKeyboard { + + /** + * Hides the keyboard if it is showing. Hiding the keyboard often + * depends on the way an app is implemented, no single strategy always + * works. + * + * @param strategy HideKeyboardStrategy. + * @param keyName a String, representing the text displayed on the button of the + * keyboard you want to press. For example: "Done". + */ + default void hideKeyboard(String strategy, String keyName) { + CommandExecutionHelper.execute(this, hideKeyboardCommand(strategy, keyName)); + } +} diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 23a9a3471..80cba36ab 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -22,6 +22,7 @@ import org.openqa.selenium.remote.CommandInfo; import org.openqa.selenium.remote.http.HttpMethod; +import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; @@ -176,4 +177,64 @@ public static ImmutableMap prepareArguments(String[] params, } return builder.build(); } + + /** + * This method forms a {@link java.util.Map} of parameters for the + * key event invocation. + * + * @param key code for the key pressed on the device. + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> pressKeyCodeCommand(int key) { + return new AbstractMap.SimpleEntry<>( + PRESS_KEY_CODE, prepareArguments("keycode", key)); + } + + /** + * This method forms a {@link java.util.Map} of parameters for the + * key event invocation. + * + * @param key code for the key pressed on the Android device. + * @param metastate metastate for the keypress. + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> pressKeyCodeCommand(int key, + Integer metastate) { + String[] parameters = new String[] {"keycode", "metastate"}; + Object[] values = new Object[] {key, metastate}; + return new AbstractMap.SimpleEntry<>( + PRESS_KEY_CODE, prepareArguments(parameters, values)); + } + + /** + * This method forms a {@link java.util.Map} of parameters for the + * long key event invocation. + * + * @param key code for the long key pressed on the device. + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> longPressKeyCodeCommand(int key) { + return new AbstractMap.SimpleEntry<>( + LONG_PRESS_KEY_CODE, prepareArguments("keycode", key)); + } + + /** + * This method forms a {@link java.util.Map} of parameters for the + * long key event invocation. + * + * @param key code for the long key pressed on the Android device. + * @param metastate metastate for the long key press. + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> longPressKeyCodeCommand(int key, + Integer metastate) { + String[] parameters = new String[] {"keycode", "metastate"}; + Object[] values = new Object[] {key, metastate}; + return new AbstractMap.SimpleEntry<>( + LONG_PRESS_KEY_CODE, prepareArguments(parameters, values)); + } } diff --git a/src/main/java/io/appium/java_client/MobileDriver.java b/src/main/java/io/appium/java_client/MobileDriver.java index 2846e73e9..57a2c71bc 100644 --- a/src/main/java/io/appium/java_client/MobileDriver.java +++ b/src/main/java/io/appium/java_client/MobileDriver.java @@ -35,7 +35,7 @@ import java.util.Map; public interface MobileDriver extends WebDriver, PerformsTouchActions, ContextAware, Rotatable, - FindsByAccessibilityId, LocationContext, DeviceActionShortcuts, + FindsByAccessibilityId, LocationContext, HidesKeyboard, HasDeviceTime, InteractsWithFiles, InteractsWithApps, HasAppStrings, FindsByClassName, FindsByCssSelector, FindsById, FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, FindsByFluentSelector, ExecutesMethod, HasSessionDetails { diff --git a/src/main/java/io/appium/java_client/PressesKeyCode.java b/src/main/java/io/appium/java_client/PressesKeyCode.java new file mode 100644 index 000000000..4ad06f104 --- /dev/null +++ b/src/main/java/io/appium/java_client/PressesKeyCode.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * 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 static io.appium.java_client.MobileCommand.longPressKeyCodeCommand; +import static io.appium.java_client.MobileCommand.pressKeyCodeCommand; + +public interface PressesKeyCode extends ExecutesMethod { + + /** + * Send a key event to the device. + * + * @param key code for the key pressed on the device. + */ + default void pressKeyCode(int key) { + CommandExecutionHelper.execute(this, pressKeyCodeCommand(key)); + } + + /** + * Send a key event along with an Android metastate to an Android device. + * Metastates are things like *shift* to get uppercase characters. + * + * @param key code for the key pressed on the Android device. + * @param metastate metastate for the keypress. + */ + default void pressKeyCode(int key, Integer metastate) { + CommandExecutionHelper.execute(this, pressKeyCodeCommand(key, metastate)); + } + + /** + * Send a long key event to the device. + * + * @param key code for the key pressed on the device. + */ + default void longPressKeyCode(int key) { + CommandExecutionHelper.execute(this, longPressKeyCodeCommand(key)); + } + + /** + * Send a long key event along with an Android metastate to an Android device. + * Metastates are things like *shift* to get uppercase characters. + * + * @param key code for the key pressed on the Android device. + * @param metastate metastate for the keypress. + */ + default void longPressKeyCode(int key, Integer metastate) { + CommandExecutionHelper.execute(this, longPressKeyCodeCommand(key, metastate)); + } +} diff --git a/src/main/java/io/appium/java_client/android/AndroidDeviceActionShortcuts.java b/src/main/java/io/appium/java_client/android/AndroidDeviceActionShortcuts.java index 16b13c264..4fa8eb101 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDeviceActionShortcuts.java +++ b/src/main/java/io/appium/java_client/android/AndroidDeviceActionShortcuts.java @@ -22,6 +22,11 @@ import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.DeviceActionShortcuts; +@Deprecated +/** + * This interface is deprecated and won't be supported anymore. + * Please use {@link io.appium.java_client.PressesKeyCode} API instead + */ public interface AndroidDeviceActionShortcuts extends DeviceActionShortcuts { /** diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 5527971b7..9a188c132 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -23,6 +23,7 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.FindsByAndroidUIAutomator; +import io.appium.java_client.PressesKeyCode; import io.appium.java_client.android.internal.JsonToAndroidElementConverter; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.service.local.AppiumDriverLocalService; @@ -46,7 +47,7 @@ */ public class AndroidDriver extends AppiumDriver - implements AndroidDeviceActionShortcuts, HasNetworkConnection, PushesFiles, StartsActivity, + implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity, FindsByAndroidUIAutomator, LocksAndroidDevice, HasSettings { private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID; diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java index ff7362857..245dba633 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -87,27 +87,18 @@ public class AndroidMobileCommandHelper extends MobileCommand { IS_LOCKED, ImmutableMap.of()); } + @Deprecated /** - * This method forms a {@link java.util.Map} of parameters for the - * key event invocation. - * - * @param key code for the key pressed on the device. - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * It is deprecated. Please use {@link MobileCommand#pressKeyCodeCommand(int)} instead. */ public static Map.Entry> pressKeyCodeCommand(int key) { return new AbstractMap.SimpleEntry<>( PRESS_KEY_CODE, prepareArguments("keycode", key)); } + @Deprecated /** - * This method forms a {@link java.util.Map} of parameters for the - * key event invocation. - * - * @param key code for the key pressed on the Android device. - * @param metastate metastate for the keypress. - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * It is deprecated. Please use {@link MobileCommand#pressKeyCodeCommand(int, Integer)} instead. */ public static Map.Entry> pressKeyCodeCommand(int key, Integer metastate) { @@ -117,27 +108,18 @@ public class AndroidMobileCommandHelper extends MobileCommand { PRESS_KEY_CODE, prepareArguments(parameters, values)); } + @Deprecated /** - * This method forms a {@link java.util.Map} of parameters for the - * long key event invocation. - * - * @param key code for the long key pressed on the device. - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * It is deprecated. Please use {@link MobileCommand#longPressKeyCodeCommand(int)} instead. */ public static Map.Entry> longPressKeyCodeCommand(int key) { return new AbstractMap.SimpleEntry<>( LONG_PRESS_KEY_CODE, prepareArguments("keycode", key)); } + @Deprecated /** - * This method forms a {@link java.util.Map} of parameters for the - * long key event invocation. - * - * @param key code for the long key pressed on the Android device. - * @param metastate metastate for the long key press. - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * It is deprecated. Please use {@link MobileCommand#longPressKeyCodeCommand(int, Integer)} instead. */ public static Map.Entry> longPressKeyCodeCommand(int key, Integer metastate) { diff --git a/src/main/java/io/appium/java_client/ios/IOSDeviceActionShortcuts.java b/src/main/java/io/appium/java_client/ios/IOSDeviceActionShortcuts.java index 190fcc6a4..122b25f14 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDeviceActionShortcuts.java +++ b/src/main/java/io/appium/java_client/ios/IOSDeviceActionShortcuts.java @@ -22,6 +22,11 @@ import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.DeviceActionShortcuts; +@Deprecated +/** + * This interface is deprecated and won't be supported anymore. + * Please use {@link io.appium.java_client.HidesKeyboardWithKeyName} and {@link ShakesDevice} API instead. + */ public interface IOSDeviceActionShortcuts extends DeviceActionShortcuts { /** diff --git a/src/main/java/io/appium/java_client/ios/IOSDriver.java b/src/main/java/io/appium/java_client/ios/IOSDriver.java index 59f1248c4..143f7ffa6 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -20,6 +20,7 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.FindsByIosUIAutomation; +import io.appium.java_client.HidesKeyboardWithKeyName; import io.appium.java_client.ios.internal.JsonToIOSElementConverter; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.service.local.AppiumDriverLocalService; @@ -49,7 +50,7 @@ */ public class IOSDriver extends AppiumDriver - implements IOSDeviceActionShortcuts, + implements HidesKeyboardWithKeyName, ShakesDevice, FindsByIosUIAutomation, LocksIOSDevice { private static final String IOS_PLATFORM = MobilePlatform.IOS; diff --git a/src/main/java/io/appium/java_client/ios/ShakesDevice.java b/src/main/java/io/appium/java_client/ios/ShakesDevice.java new file mode 100644 index 000000000..abd601852 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/ShakesDevice.java @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * 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.CommandExecutionHelper; +import io.appium.java_client.ExecutesMethod; + +import static io.appium.java_client.ios.IOSMobileCommandHelper.shakeCommand; + +public interface ShakesDevice extends ExecutesMethod { + + /** + * Simulate shaking the device. + */ + default void shake() { + CommandExecutionHelper.execute(this, shakeCommand()); + } +} From 4ea6635ca6d04330e0f0a9e2aa2e9382a2a6c071 Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Sun, 6 Nov 2016 15:28:24 +0300 Subject: [PATCH 04/20] #456 FIX #454 FIX: MultiTouchAction refactoring - new methods were added to MultiTouchAction - AppiumDriver methods which perform multiple touch actions were marked as Deprecated - Constructors of TouchAction and MultiTouchAction were changed. Now it accepts any instance that can perform touch action and multiple touch actions. --- .../io/appium/java_client/AppiumDriver.java | 58 ++++++-- .../appium/java_client/MultiTouchAction.java | 131 ++++++++++++------ .../io/appium/java_client/TouchAction.java | 23 +-- .../android/AndroidGestureTest.java | 5 +- .../java_client/ios/IOSGesturesTest.java | 7 +- 5 files changed, 158 insertions(+), 66 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index bc6b3be66..906064efc 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -28,8 +28,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; import org.openqa.selenium.DeviceRotation; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; @@ -213,8 +211,10 @@ public List findElementsByXPath(String using) { return executeMethod; } + @Deprecated /** - * @see TouchableElement#tap(int, WebElement, int). + * This method is deprecated and it is going to be removed soon. + * Please use {@link MultiTouchAction#tap(int, WebElement, int)}. */ public void tap(int fingers, WebElement element, int duration) { MultiTouchAction multiTouch = new MultiTouchAction(this); @@ -226,8 +226,10 @@ public void tap(int fingers, WebElement element, int duration) { multiTouch.perform(); } + @Deprecated /** - * @see TouchableElement#tap(int, int, int, int). + * This method is deprecated and it is going to be removed soon. + * Please use {@link MultiTouchAction#tap(int, int, int, int)}. */ public void tap(int fingers, int x, int y, int duration) { MultiTouchAction multiTouch = new MultiTouchAction(this); @@ -246,8 +248,10 @@ public void swipe(int startx, int starty, int endx, int endy, int duration) { } + @Deprecated /** - * @see TouchableElement#pinch(WebElement). + * This method is deprecated and it is going to be removed soon. + * Please use {@link MultiTouchAction#pinch(WebElement)}. */ public void pinch(WebElement el) { MultiTouchAction multiTouch = new MultiTouchAction(this); @@ -255,17 +259,34 @@ public void pinch(WebElement el) { multiTouch.pinch(el).perform(); } + @Deprecated /** - * @see TouchableElement#pinch(int, int). + * This method is deprecated and it is going to be removed soon. + * Please use {@link MultiTouchAction#pinch(int, int, int, int)} or + * {@link MultiTouchAction#pinch(int, int, int)} */ public void pinch(int x, int y) { MultiTouchAction multiTouch = new MultiTouchAction(this); - multiTouch.pinch(x, y).perform(); + int scrHeight = this.manage().window().getSize().getHeight(); + int yOffset = 100; + + if (y - 100 < 0) { + yOffset = y; + } else if (y + 100 > scrHeight) { + yOffset = scrHeight - y; + } + + TouchAction action0 = new TouchAction(this).press(x, y - yOffset).moveTo(x, y).release(); + TouchAction action1 = new TouchAction(this).press(x, y + yOffset).moveTo(x, y).release(); + + multiTouch.add(action0).add(action1).perform(); } + @Deprecated /** - * @see TouchableElement#zoom(WebElement). + * This method is deprecated and it is going to be removed soon. + * Please use {@link MultiTouchAction#zoom(WebElement)}. */ public void zoom(WebElement el) { MultiTouchAction multiTouch = new MultiTouchAction(this); @@ -273,13 +294,28 @@ public void zoom(WebElement el) { multiTouch.zoom(el).perform(); } + @Deprecated /** - * @see TouchableElement#zoom(int, int). + * This method is deprecated and it is going to be removed soon. + * Please use {@link MultiTouchAction#zoom(int, int, int, int)} or + * {@link MultiTouchAction#zoom(int, int, int)}. */ public void zoom(int x, int y) { MultiTouchAction multiTouch = new MultiTouchAction(this); - multiTouch.zoom(x, y).perform(); + int scrHeight = this.manage().window().getSize().getHeight(); + int yOffset = 100; + + if (y - 100 < 0) { + yOffset = y; + } else if (y + 100 > scrHeight) { + yOffset = scrHeight - y; + } + + TouchAction action0 = new TouchAction(this).press(x, y).moveTo(0, -yOffset).release(); + TouchAction action1 = new TouchAction(this).press(x, y).moveTo(0, yOffset).release(); + + multiTouch.add(action0).add(action1).perform(); } @Override public WebDriver context(String name) { @@ -349,11 +385,13 @@ public void zoom(int x, int y) { locationContext.setLocation(location); } + @Deprecated private TouchAction createTap(WebElement element, int duration) { TouchAction tap = new TouchAction(this); return tap.press(element).waitAction(duration).release(); } + @Deprecated private TouchAction createTap(int x, int y, int duration) { TouchAction tap = new TouchAction(this); return tap.press(x, y).waitAction(duration).release(); diff --git a/src/main/java/io/appium/java_client/MultiTouchAction.java b/src/main/java/io/appium/java_client/MultiTouchAction.java index 053a62307..f92fb3063 100644 --- a/src/main/java/io/appium/java_client/MultiTouchAction.java +++ b/src/main/java/io/appium/java_client/MultiTouchAction.java @@ -41,12 +41,13 @@ * Calling perform() sends the action command to the Mobile Driver. Otherwise, more and * more actions can be chained. */ -@SuppressWarnings({"rawtypes", "unchecked"}) public class MultiTouchAction { +@SuppressWarnings({"rawtypes", "unchecked"}) +public class MultiTouchAction { - ImmutableList.Builder actions; - private MobileDriver driver; + private ImmutableList.Builder actions; + private PerformsTouchActions driver; - public MultiTouchAction(MobileDriver driver) { + public MultiTouchAction(PerformsTouchActions driver) { this.driver = driver; actions = ImmutableList.builder(); } @@ -92,11 +93,9 @@ protected ImmutableMap getParameters() { } /** - * @see TouchableElement#pinch(WebElement). + * Creates few combined touch actions which performs the pinching on the given elements. */ public MultiTouchAction pinch(WebElement el) { - MultiTouchAction multiTouch = new MultiTouchAction(driver); - Dimension dimensions = el.getSize(); Point upperLeft = el.getLocation(); Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, @@ -110,36 +109,45 @@ public MultiTouchAction pinch(WebElement el) { new TouchAction(driver).press(el, center.getX(), center.getY() + yOffset).moveTo(el) .release(); - return multiTouch.add(action0).add(action1); + this.add(action0).add(action1); + return this; } /** - * @see TouchableElement#pinch(int, int). + * Creates few combined touch actions which performs the pinching by given coordinates and offsets. + * + * @param x is a x-coordinate to perform the pinching to + * @param y is an y-coordinate to perform the pinching to + * @param xOffset is an +/- offset from the given x-coordinate to perform the pinching to + * @param yOffset is an +/- offset from the given y-coordinate to perform the pinching to + * @return the self-reference */ - public MultiTouchAction pinch(int x, int y) { - MultiTouchAction multiTouch = new MultiTouchAction(driver); - - int scrHeight = driver.manage().window().getSize().getHeight(); - int yOffset = 100; + public MultiTouchAction pinch(int x, int y, int xOffset, int yOffset) { + TouchAction action0 = new TouchAction(driver).press(x + xOffset, y - yOffset) + .moveTo(- xOffset, yOffset).release(); + TouchAction action1 = new TouchAction(driver).press(x - xOffset, y + yOffset) + .moveTo(xOffset, -yOffset).release(); - if (y - 100 < 0) { - yOffset = y; - } else if (y + 100 > scrHeight) { - yOffset = scrHeight - y; - } - - TouchAction action0 = new TouchAction(driver).press(x, y - yOffset).moveTo(x, y).release(); - TouchAction action1 = new TouchAction(driver).press(x, y + yOffset).moveTo(x, y).release(); + this.add(action0).add(action1); + return this; + } - return multiTouch.add(action0).add(action1); + /** + * Creates few combined touch actions which performs the vertical pinching by given coordinates and y-Offset. + * + * @param x is a x-coordinate to perform the pinching to + * @param y is an y-coordinate to perform the pinching to + * @param yOffset is an +/- offset from the given y-coordinate to perform the pinching to + * @return the self-reference + */ + public MultiTouchAction pinch(int x, int y, int yOffset) { + return pinch(x, y, 0, yOffset); } /** - * @see TouchableElement#zoom(WebElement). + * Creates few combined touch actions which performs the zooming on the given elements. */ public MultiTouchAction zoom(WebElement el) { - MultiTouchAction multiTouch = new MultiTouchAction(driver); - Dimension dimensions = el.getSize(); Point upperLeft = el.getLocation(); Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, @@ -151,27 +159,70 @@ public MultiTouchAction zoom(WebElement el) { TouchAction action1 = new TouchAction(driver).press(center.getX(), center.getY()) .moveTo(el, center.getX(), center.getY() + yOffset).release(); - return multiTouch.add(action0).add(action1); + this.add(action0).add(action1); + return this; } /** - * @see TouchableElement#zoom(int, int). + * Creates few combined touch actions which performs the zooming by given coordinates and x/y-Offset value. + * + * @param x is a x-coordinate to perform the zooming from + * @param y is a y-coordinate to perform the zooming from + * @param xOffset is an +/- offset from the given x-coordinate to perform the zooming from + * @param yOffset is an +/- offset from the given y-coordinate to perform the zooming from + * @return the self-reference */ - public MultiTouchAction zoom(int x, int y) { - MultiTouchAction multiTouch = new MultiTouchAction(driver); + public MultiTouchAction zoom(int x, int y, int xOffset, int yOffset) { + TouchAction action0 = new TouchAction(driver).press(x, y) + .moveTo(xOffset, -yOffset).release(); + TouchAction action1 = new TouchAction(driver).press(x, y) + .moveTo(-xOffset, yOffset).release(); - int scrHeight = driver.manage().window().getSize().getHeight(); - int yOffset = 100; + return this.add(action0).add(action1); + } - if (y - 100 < 0) { - yOffset = y; - } else if (y + 100 > scrHeight) { - yOffset = scrHeight - y; - } + /** + * Creates few combined touch actions which performs the vertical zooming by given coordinates and x/y-Offset value. + * + * @param x is a x-coordinate to perform the zooming from + * @param y is a y-coordinate to perform the zooming from + * @param yOffset is an +/- offset from the given y-coordinate to perform the zooming from + * @return the self-reference + */ + public MultiTouchAction zoom(int x, int y, int yOffset) { + return zoom(x, y, 0, yOffset); + } - TouchAction action0 = new TouchAction(driver).press(x, y).moveTo(0, -yOffset).release(); - TouchAction action1 = new TouchAction(driver).press(x, y).moveTo(0, yOffset).release(); + /** + * Creates the tapping by few finders using given coordinates. + * + * @param fingers is a count of fingers to tap + * @param x coordinate + * @param y coordinate + * @param duration is a time for the tapping in milliseconds + * @return + */ + public MultiTouchAction tap(int fingers, int x, int y, int duration) { + for (int i = 0; i < fingers; i++) { + TouchAction tap = new TouchAction(driver); + this.add(tap.press(x, y).waitAction(duration).release()); + } + return this; + } - return multiTouch.add(action0).add(action1); + /** + * Creates the tapping by few finders on the element. + * + * @param fingers is a count of fingers to tap + * @param element to be tapped + * @param duration is a time for the tapping in milliseconds + * @return + */ + public MultiTouchAction tap(int fingers, WebElement element, int duration) { + for (int i = 0; i < fingers; i++) { + TouchAction tap = new TouchAction(driver); + this.add(tap.press(element).waitAction(duration).release()); + } + return this; } } diff --git a/src/main/java/io/appium/java_client/TouchAction.java b/src/main/java/io/appium/java_client/TouchAction.java index c29e815e2..e87120cf6 100644 --- a/src/main/java/io/appium/java_client/TouchAction.java +++ b/src/main/java/io/appium/java_client/TouchAction.java @@ -28,18 +28,19 @@ * See the Webriver 3 spec * https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html * The flow is to chain individual touch actions into an entire gesture. e.g. - * TouchAction action = new TouchAction(driver); + * TouchAction action = new TouchAction(performsTouchActions); * action.press(element).waitAction(300).moveTo(element1).release().perform(); * Calling perform() sends the action command to the Mobile Driver. Otherwise, * more and more actions can be chained. */ -@SuppressWarnings({"rawtypes", "unchecked"}) public class TouchAction { +@SuppressWarnings({"rawtypes", "unchecked"}) +public class TouchAction { - protected ImmutableList.Builder parameterBuilder; - private MobileDriver driver; + private ImmutableList.Builder parameterBuilder; + private PerformsTouchActions performsTouchActions; - public TouchAction(MobileDriver driver) { - this.driver = driver; + public TouchAction(PerformsTouchActions driver) { + this.performsTouchActions = driver; parameterBuilder = ImmutableList.builder(); } @@ -306,7 +307,7 @@ public TouchAction longPress(WebElement el, int x, int y, int duration) { } /** - * Cancel this action, if it was partially completed by the driver. + * Cancel this action, if it was partially completed by the performsTouchActions. */ public void cancel() { ActionParameter action = new ActionParameter("wait"); @@ -315,12 +316,12 @@ public void cancel() { } /** - * Perform this chain of actions on the driver. + * Perform this chain of actions on the performsTouchActions. * * @return this TouchAction, for possible segmented-touches. */ public TouchAction perform() { - driver.performTouchAction(this); + performsTouchActions.performTouchAction(this); return this; } @@ -348,7 +349,7 @@ protected void clearParameters() { */ protected class ActionParameter { private String actionName; - private ImmutableMap.Builder optionsBuilder; + private ImmutableMap.Builder optionsBuilder; public ActionParameter(String actionName) { this.actionName = actionName; @@ -362,7 +363,7 @@ public ActionParameter(String actionName, HasIdentity el) { } public ImmutableMap getParameterMap() { - ImmutableMap.Builder builder = ImmutableMap.builder(); + ImmutableMap.Builder builder = ImmutableMap.builder(); builder.put("action", actionName).put("options", optionsBuilder.build()); return builder.build(); } 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 69f7ffcba..dcc6ca822 100644 --- a/src/test/java/io/appium/java_client/android/AndroidGestureTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidGestureTest.java @@ -35,14 +35,15 @@ public class AndroidGestureTest extends BaseAndroidTest { driver.startActivity("io.appium.android.apis", ".view.Buttons1"); Point point = driver.findElementById("io.appium.android.apis:id/button_toggle").getLocation(); - driver.tap(1, point.x + 20, point.y + 30, 1000); + new MultiTouchAction(driver).tap(1, point.x + 20, point.y + 30, 1000).perform(); assertEquals("ON" ,driver .findElementById("io.appium.android.apis:id/button_toggle").getText()); } @Test public void singleElementTapTest() throws Exception { driver.startActivity("io.appium.android.apis", ".view.Buttons1"); - driver.tap(1, driver.findElementById("io.appium.android.apis:id/button_toggle"), 1000); + new MultiTouchAction(driver).tap(1, driver.findElementById("io.appium.android.apis:id/button_toggle"), 1000) + .perform(); assertEquals("ON" ,driver .findElementById("io.appium.android.apis:id/button_toggle").getText()); } diff --git a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java index 827d2dff9..4e9914beb 100644 --- a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import io.appium.java_client.MobileElement; +import io.appium.java_client.MultiTouchAction; import io.appium.java_client.SwipeElementDirection; import org.junit.Test; @@ -30,18 +31,18 @@ public class IOSGesturesTest extends BaseIOSTest { driver.findElementById("IntegerB").sendKeys("4"); MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); - driver.tap(2, e, 2000); + new MultiTouchAction(driver).tap(2, e, 2000).perform(); assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6"); } @Test public void zoomTest() { MobileElement e = driver.findElementById("IntegerA"); - driver.zoom(e); + new MultiTouchAction(driver).zoom(e).perform(); } @Test public void pinchTest() { MobileElement e = driver.findElementById("IntegerA"); - driver.pinch(e); + new MultiTouchAction(driver).pinch(e).perform(); } @Test public void horizontalSwipingTest() { From 34a718bcc5eb8966b196df7c610d15390b8f3bab Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Tue, 8 Nov 2016 15:50:47 +0300 Subject: [PATCH 05/20] #456 FIX #454 FIX: New CreatesSwipeAction API - the new interface CreatesSwipeAction was added. - the reversion of last changes of TouchableElement. - the `swipe` is deprecated method. --- .../java_client/CreatesSwipeAction.java | 96 +++++++++++++ .../appium/java_client/TouchableElement.java | 134 ++---------------- 2 files changed, 111 insertions(+), 119 deletions(-) create mode 100644 src/main/java/io/appium/java_client/CreatesSwipeAction.java diff --git a/src/main/java/io/appium/java_client/CreatesSwipeAction.java b/src/main/java/io/appium/java_client/CreatesSwipeAction.java new file mode 100644 index 000000000..335e43893 --- /dev/null +++ b/src/main/java/io/appium/java_client/CreatesSwipeAction.java @@ -0,0 +1,96 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * 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.WebElement; + +public interface CreatesSwipeAction { + + /** + * Creates combined touch action for the swiping by start/end coordinates. + * + * @param startX x-coordinate to swipe from + * @param startY y-coordinate to swipe from + * @param endX x-coordinate to swipe to + * @param endY y-coordinate to swipe to + * @param duration in milliseconds + * @return an instance of combined {@link TouchAction} + */ + TouchAction swipe(int startX, int startY, int endX, int endY, int duration); + + /** + * Creates combined touch action for the swiping from given coordinates to the given element. + * + * @param startX x-coordinate to swipe from + * @param startY y-coordinate to swipe from + * @param element an element to swipe to + * @param duration in milliseconds + * @return an instance of combined {@link TouchAction} + */ + TouchAction swipe(int startX, int startY, WebElement element, int duration); + + /** + * Creates combined touch action for the swiping from one element to another. + * + * @param element2 an element to swipe to + * @param element2 an element to swipe to + * @param duration in milliseconds + * @return an instance of combined {@link TouchAction} + */ + TouchAction swipe(WebElement element1, WebElement element2, int duration); + + + /** + * Creates combined touch action for the swiping inside an element. + * + * @param element an element where the swiping is performed + * @param direction is the direction to perform the swiping inside the element + * @param duration in milliseconds + * @return an instance of combined {@link TouchAction} + */ + TouchAction swipe(WebElement element, SwipeElementDirection direction, int duration); + + /** + * Creates combined touch action for the swiping inside an element using some offset from its + * borders. + * + * @param element an element where the swiping is performed + * @param direction is the direction to perform the swiping inside the element + * @param offsetFromStartBorder 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 in milliseconds + * @return an instance of combined {@link TouchAction} + * @throws IllegalCoordinatesException when resulted coordinates are out of the + * element borders or disagree with the given direction. + */ + TouchAction swipe(WebElement element, SwipeElementDirection direction, int offsetFromStartBorder, + int offsetFromEndBorder, + int duration) throws IllegalCoordinatesException; +} diff --git a/src/main/java/io/appium/java_client/TouchableElement.java b/src/main/java/io/appium/java_client/TouchableElement.java index a66dbf028..07b2e0add 100644 --- a/src/main/java/io/appium/java_client/TouchableElement.java +++ b/src/main/java/io/appium/java_client/TouchableElement.java @@ -73,61 +73,6 @@ public interface TouchableElement extends WebElement, Find List findElementsByXPath(String xPath); - /** - * 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. - */ - void tap(int fingers, int duration); - - /** - * Convenience method for tapping a position on the screen. - * - * @param fingers number of fingers/appendages to tap with. - * @param x x coordinate. - * @param y y coordinate. - * @param duration how long between pressing down, and lifting fingers/appendages. - */ - void tap(int fingers, int x, int y, int duration); - - /** - * Convenience method for tapping the center of an element on the screen. - * - * @param fingers number of fingers/appendages to tap with. - * @param element element to tap. - * @param duration how long between pressing down, and lifting fingers/appendages. - */ - void tap(int fingers, WebElement element, int duration); - - /** - * Convenience method for pinching an element on the screen. - * "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 at a distance, - * 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. - * - * @param x x coordinate to terminate the pinch on. - * @param y y coordinate to terminate the pinch on. - */ - void pinch(int x, int y); - - /** - * Convenience method for pinching an element on the screen. - * "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. - * - * @param el The element to pinch. - */ - void pinch(WebElement el); - /** * Convenience method for pinching the given element. * "pinching" refers to the action of two appendages pressing the screen @@ -141,33 +86,12 @@ public interface TouchableElement extends WebElement, Find void pinch(); /** - * Convenience method for "zooming in" on an element on the screen. - * "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. - * - * @param x x coordinate to start zoom on. - * @param y y coordinate to start zoom on. - */ - void zoom(int x, int y); - - /** - * Convenience method for "zooming in" on an element on the screen. - * "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. + * Convenience method for tapping the center of the given element. * - * @param el The element to pinch. + * @param fingers number of fingers/appendages to tap with. + * @param duration how long between pressing down, and lifting fingers/appendages. */ - void zoom(WebElement el); + void tap(int fingers, int duration); /** * Convenience method for "zooming in" on the given element. @@ -180,50 +104,22 @@ public interface TouchableElement extends WebElement, Find */ void zoom(); + + @Deprecated /** - * 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. + * This method is deprecated and it is going to be removed. + * Please use the {@link CreatesSwipeAction#swipe(WebElement, SwipeElementDirection, int)} + * instead. */ void swipe(SwipeElementDirection direction, int duration); - /** - * Convenience method for swiping across the screen. - * - * @param startx starting x coordinate. - * @param starty starting y coordinate. - * @param endx ending x coordinate. - * @param endy ending y coordinate. - * @param duration amount of time in milliseconds for the entire swipe action to take - */ - void swipe(int startx, int starty, int endx, int endy, int duration); + @Deprecated /** - * Convenience method for swiping on the given element to the given direction. - * - * @param direction direction UP, DOWN, LEFT, RIGHT. - * @param offsetFromStartBorder 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. + * This method is deprecated and it is going to be removed. + * Please use the {@link CreatesSwipeAction#swipe(WebElement, SwipeElementDirection, int, int, int)} + * instead. */ void swipe(SwipeElementDirection direction, int offsetFromStartBorder, int offsetFromEndBorder, - int duration) throws IllegalCoordinatesException; -} + int duration) throws IllegalCoordinatesException; +} \ No newline at end of file From e890280b8c12249328107368f0486b69c273a049 Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Tue, 8 Nov 2016 15:55:02 +0300 Subject: [PATCH 06/20] #456 FIX #454 FIX: Forgot to commit this change --- .../io/appium/java_client/MobileElement.java | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 05c3ab6fd..469d2c7b3 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -21,7 +21,6 @@ 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 java.util.List; @@ -47,42 +46,14 @@ public Point getCenter() { ((AppiumDriver) parent).tap(fingers, this, duration); } - @Override public void tap(int fingers, int x, int y, int duration) { - ((AppiumDriver) parent).tap(fingers, x, y, duration); - } - - @Override public void tap(int fingers, WebElement element, int duration) { - ((AppiumDriver) parent).tap(fingers, element, duration); - } - @Override public void pinch() { ((AppiumDriver) parent).pinch(this); } - @Override public void pinch(int x, int y) { - ((AppiumDriver) parent).pinch(x, y); - } - - @Override public void pinch(WebElement el) { - ((AppiumDriver) parent).pinch(el); - } - @Override public void zoom() { ((AppiumDriver) parent).zoom(this); } - @Override public void zoom(int x, int y) { - ((AppiumDriver) parent).zoom(x, y); - } - - @Override public void zoom(WebElement el) { - ((AppiumDriver) parent).zoom(el); - } - - @Override public void swipe(int startx, int starty, int endx, int endy, int duration) { - ((AppiumDriver) parent).swipe(startx, startx, endx, endy ,duration); - } - @Override public void swipe(SwipeElementDirection direction, int duration) { direction.swipe((AppiumDriver) parent, this, 0, 0, duration); } From 4b87991eb404ef6549caa331e2527a1cb04e59d7 Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Wed, 9 Nov 2016 17:56:31 +0300 Subject: [PATCH 07/20] #456 FIX #454 FIX: CreatesSwipeAction API was implemented - CreatesSwipeAction API was implemented - SwipeElementDirection was redesigned - constructors of TouchAction and MultiTouchAction were improved. --- .../java_client/CreatesSwipeAction.java | 11 +++-- .../io/appium/java_client/MobileElement.java | 17 +++++-- .../appium/java_client/MultiTouchAction.java | 44 +++++++++---------- .../java_client/SwipeElementDirection.java | 7 ++- .../io/appium/java_client/TouchAction.java | 4 +- .../android/AndroidTouchAction.java | 28 +++++++----- .../java_client/ios/IOSTouchAction.java | 32 ++++++++------ 7 files changed, 86 insertions(+), 57 deletions(-) diff --git a/src/main/java/io/appium/java_client/CreatesSwipeAction.java b/src/main/java/io/appium/java_client/CreatesSwipeAction.java index 335e43893..856d2d095 100644 --- a/src/main/java/io/appium/java_client/CreatesSwipeAction.java +++ b/src/main/java/io/appium/java_client/CreatesSwipeAction.java @@ -62,7 +62,9 @@ public interface CreatesSwipeAction { * @param duration in milliseconds * @return an instance of combined {@link TouchAction} */ - TouchAction swipe(WebElement element, SwipeElementDirection direction, int duration); + default TouchAction swipe(MobileElement element, SwipeElementDirection direction, int duration) { + return direction.swipe(this, element, 0, 0, duration); + } /** * Creates combined touch action for the swiping inside an element using some offset from its @@ -90,7 +92,10 @@ public interface CreatesSwipeAction { * @throws IllegalCoordinatesException when resulted coordinates are out of the * element borders or disagree with the given direction. */ - TouchAction swipe(WebElement element, SwipeElementDirection direction, int offsetFromStartBorder, + default TouchAction swipe(MobileElement element, SwipeElementDirection direction, int offsetFromStartBorder, int offsetFromEndBorder, - int duration) throws IllegalCoordinatesException; + int duration) throws IllegalCoordinatesException { + return direction.swipe(this, element, offsetFromStartBorder, offsetFromEndBorder, + duration); + } } diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 469d2c7b3..1671c71ea 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -26,7 +26,7 @@ import java.util.List; @SuppressWarnings({"unchecked"}) -public abstract class MobileElement +public class MobileElement extends DefaultGenericMobileElement { protected FileDetector fileDetector; @@ -54,14 +54,23 @@ public Point getCenter() { ((AppiumDriver) parent).zoom(this); } + @Deprecated + /** + * This method does nothing. It is going to be removed. + * Please use {@link CreatesSwipeAction#swipe(MobileElement, SwipeElementDirection, int)} instead. + */ @Override public void swipe(SwipeElementDirection direction, int duration) { - direction.swipe((AppiumDriver) parent, this, 0, 0, duration); + //does nothing } + @Deprecated + /** + * This method does nothing. It is going to be removed. + * Please use {@link CreatesSwipeAction#swipe(MobileElement, SwipeElementDirection, int, int, int)} instead. + */ @Override public void swipe(SwipeElementDirection direction, int offsetFromStartBorder, int offsetFromEndBorder, int duration) throws IllegalCoordinatesException { - direction.swipe((AppiumDriver) parent, this, offsetFromStartBorder, offsetFromEndBorder, - duration); + //does nothing } @Override public List findElements(By by) { diff --git a/src/main/java/io/appium/java_client/MultiTouchAction.java b/src/main/java/io/appium/java_client/MultiTouchAction.java index f92fb3063..f6af39b2f 100644 --- a/src/main/java/io/appium/java_client/MultiTouchAction.java +++ b/src/main/java/io/appium/java_client/MultiTouchAction.java @@ -30,11 +30,11 @@ * The MultiTouchAction object is a collection of TouchAction objects * (remember that TouchAction objects are in turn, a chain of individual actions) * Add multiple TouchAction objects using the add() method. - * When perform() method is called, all actions are sent to the driver. - * The driver performs the first step of each TouchAction object simultaneously as a multi-touch + * When perform() method is called, all actions are sent to the performsTouchActions. + * The performsTouchActions performs the first step of each TouchAction object simultaneously as a multi-touch * "execution group". Conceptually, the number of TouchAction objects added to the MultiTouchAction * is equal to the number of "fingers" or other appendages or tools touching the screen at the - * same time as part of this multi-gesture. Then the driver performs the second step of each + * same time as part of this multi-gesture. Then the performsTouchActions performs the second step of each * TouchAction object and another "execution group", and the third, and so on. * Using a waitAction() action within a TouchAction takes up one of the slots in an * "execution group", so these can be used to sync up complex actions. @@ -45,10 +45,10 @@ public class MultiTouchAction { private ImmutableList.Builder actions; - private PerformsTouchActions driver; + private PerformsTouchActions performsTouchActions; - public MultiTouchAction(PerformsTouchActions driver) { - this.driver = driver; + public MultiTouchAction(PerformsTouchActions performsTouchActions) { + this.performsTouchActions = performsTouchActions; actions = ImmutableList.builder(); } @@ -65,15 +65,15 @@ public MultiTouchAction add(TouchAction action) { } /** - * Perform the multi-touch action on the mobile driver. + * Perform the multi-touch action on the mobile performsTouchActions. */ public void perform() { int size = actions.build().size(); if (size > 1) { - driver.performMultiTouchAction(this); + performsTouchActions.performMultiTouchAction(this); } else if (size == 1) { //android doesn't like having multi-touch actions with only a single TouchAction... - driver.performTouchAction(actions.build().get(0)); + performsTouchActions.performTouchAction(actions.build().get(0)); } else { throw new MissingParameterException( "MultiTouch action must have at least one TouchAction " @@ -103,10 +103,10 @@ public MultiTouchAction pinch(WebElement el) { int yOffset = center.getY() - upperLeft.getY(); TouchAction action0 = - new TouchAction(driver).press(el, center.getX(), center.getY() - yOffset).moveTo(el) + new TouchAction(performsTouchActions).press(el, center.getX(), center.getY() - yOffset).moveTo(el) .release(); TouchAction action1 = - new TouchAction(driver).press(el, center.getX(), center.getY() + yOffset).moveTo(el) + new TouchAction(performsTouchActions).press(el, center.getX(), center.getY() + yOffset).moveTo(el) .release(); this.add(action0).add(action1); @@ -123,9 +123,9 @@ public MultiTouchAction pinch(WebElement el) { * @return the self-reference */ public MultiTouchAction pinch(int x, int y, int xOffset, int yOffset) { - TouchAction action0 = new TouchAction(driver).press(x + xOffset, y - yOffset) + TouchAction action0 = new TouchAction(performsTouchActions).press(x + xOffset, y - yOffset) .moveTo(- xOffset, yOffset).release(); - TouchAction action1 = new TouchAction(driver).press(x - xOffset, y + yOffset) + TouchAction action1 = new TouchAction(performsTouchActions).press(x - xOffset, y + yOffset) .moveTo(xOffset, -yOffset).release(); this.add(action0).add(action1); @@ -145,7 +145,7 @@ public MultiTouchAction pinch(int x, int y, int yOffset) { } /** - * Creates few combined touch actions which performs the zooming on the given elements. + * Creates few combined touch actions which performs the zooming on the given element. */ public MultiTouchAction zoom(WebElement el) { Dimension dimensions = el.getSize(); @@ -154,9 +154,9 @@ public MultiTouchAction zoom(WebElement el) { upperLeft.getY() + dimensions.getHeight() / 2); int yOffset = center.getY() - upperLeft.getY(); - TouchAction action0 = new TouchAction(driver).press(center.getX(), center.getY()) + TouchAction action0 = new TouchAction(performsTouchActions).press(center.getX(), center.getY()) .moveTo(el, center.getX(), center.getY() - yOffset).release(); - TouchAction action1 = new TouchAction(driver).press(center.getX(), center.getY()) + TouchAction action1 = new TouchAction(performsTouchActions).press(center.getX(), center.getY()) .moveTo(el, center.getX(), center.getY() + yOffset).release(); this.add(action0).add(action1); @@ -173,9 +173,9 @@ public MultiTouchAction zoom(WebElement el) { * @return the self-reference */ public MultiTouchAction zoom(int x, int y, int xOffset, int yOffset) { - TouchAction action0 = new TouchAction(driver).press(x, y) + TouchAction action0 = new TouchAction(performsTouchActions).press(x, y) .moveTo(xOffset, -yOffset).release(); - TouchAction action1 = new TouchAction(driver).press(x, y) + TouchAction action1 = new TouchAction(performsTouchActions).press(x, y) .moveTo(-xOffset, yOffset).release(); return this.add(action0).add(action1); @@ -200,11 +200,11 @@ public MultiTouchAction zoom(int x, int y, int yOffset) { * @param x coordinate * @param y coordinate * @param duration is a time for the tapping in milliseconds - * @return + * @return the self-reference */ public MultiTouchAction tap(int fingers, int x, int y, int duration) { for (int i = 0; i < fingers; i++) { - TouchAction tap = new TouchAction(driver); + TouchAction tap = new TouchAction(performsTouchActions); this.add(tap.press(x, y).waitAction(duration).release()); } return this; @@ -216,11 +216,11 @@ public MultiTouchAction tap(int fingers, int x, int y, int duration) { * @param fingers is a count of fingers to tap * @param element to be tapped * @param duration is a time for the tapping in milliseconds - * @return + * @return the self-reference */ public MultiTouchAction tap(int fingers, WebElement element, int duration) { for (int i = 0; i < fingers; i++) { - TouchAction tap = new TouchAction(driver); + TouchAction tap = new TouchAction(performsTouchActions); this.add(tap.press(element).waitAction(duration).release()); } return this; diff --git a/src/main/java/io/appium/java_client/SwipeElementDirection.java b/src/main/java/io/appium/java_client/SwipeElementDirection.java index add3c29ed..5098ad0de 100644 --- a/src/main/java/io/appium/java_client/SwipeElementDirection.java +++ b/src/main/java/io/appium/java_client/SwipeElementDirection.java @@ -16,6 +16,7 @@ package io.appium.java_client; +import org.aspectj.lang.annotation.SuppressAjWarnings; import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; @@ -142,6 +143,7 @@ public enum SwipeElementDirection { } }; + @SuppressAjWarnings("unused") static void checkYCoordinate(int y, Point location, Dimension size, int offSet) throws IllegalCoordinatesException { int bottom = location.getY() + size.getHeight(); @@ -157,6 +159,7 @@ static void checkYCoordinate(int y, Point location, Dimension size, int offSet) } + @SuppressAjWarnings("unused") static void checkXCoordinate(int x, Point location, Dimension size, int offSet) throws IllegalCoordinatesException { int right = location.getX() + size.getWidth(); @@ -182,7 +185,7 @@ static void checkXCoordinate(int x, 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, + public TouchAction swipe(CreatesSwipeAction createsSwipeAction, MobileElement element, int offset1, int offset2, int duration) throws IllegalCoordinatesException { Point p = element.getCenter(); Point location = element.getLocation(); @@ -193,6 +196,6 @@ void swipe(AppiumDriver driver, MobileElement element, int offset1, int offse int endY = getEndY(p, location, size, offset2); checkDirection(startX, startY, endX, endY); - driver.swipe(startX, startY, endX, endY, duration); + return createsSwipeAction.swipe(startX, startY, endX, endY, duration); } } diff --git a/src/main/java/io/appium/java_client/TouchAction.java b/src/main/java/io/appium/java_client/TouchAction.java index e87120cf6..58e547103 100644 --- a/src/main/java/io/appium/java_client/TouchAction.java +++ b/src/main/java/io/appium/java_client/TouchAction.java @@ -39,8 +39,8 @@ public class TouchAction { private ImmutableList.Builder parameterBuilder; private PerformsTouchActions performsTouchActions; - public TouchAction(PerformsTouchActions driver) { - this.performsTouchActions = driver; + public TouchAction(PerformsTouchActions performsTouchActions) { + this.performsTouchActions = performsTouchActions; parameterBuilder = ImmutableList.builder(); } diff --git a/src/main/java/io/appium/java_client/android/AndroidTouchAction.java b/src/main/java/io/appium/java_client/android/AndroidTouchAction.java index 94134ee72..6ece07766 100644 --- a/src/main/java/io/appium/java_client/android/AndroidTouchAction.java +++ b/src/main/java/io/appium/java_client/android/AndroidTouchAction.java @@ -1,22 +1,28 @@ package io.appium.java_client.android; -import io.appium.java_client.MobileDriver; +import io.appium.java_client.CreatesSwipeAction; +import io.appium.java_client.PerformsTouchActions; import io.appium.java_client.TouchAction; -import io.appium.java_client.TouchableElement; +import org.openqa.selenium.WebElement; -public class AndroidTouchAction extends TouchAction { +public class AndroidTouchAction extends TouchAction implements CreatesSwipeAction { - public AndroidTouchAction(MobileDriver driver) { - super(driver); + public AndroidTouchAction(PerformsTouchActions performsTouchActions) { + super(performsTouchActions); } - /** - * @see TouchableElement#swipe(int, int, int, int, int). - */ - @Deprecated protected TouchAction swipe(int startx, int starty, int endx, int endy, int duration) { + @Override + public TouchAction swipe(int startX, int startY, int endx, int endy, int duration) { + return press(startX, startY).waitAction(duration).moveTo(endx, endy).release(); + } - // appium converts press-wait-moveto-release to a swipe action - return press(startx, starty).waitAction(duration).moveTo(endx, endy).release(); + @Override + public TouchAction swipe(int startX, int startY, WebElement element, int duration) { + return press(startX, startY).waitAction(duration).moveTo(element).release(); + } + @Override + public TouchAction swipe(WebElement element1, WebElement element2, int duration) { + return press(element1).waitAction(duration).moveTo(element2).release(); } } diff --git a/src/main/java/io/appium/java_client/ios/IOSTouchAction.java b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java index dee46ae84..c599c3101 100644 --- a/src/main/java/io/appium/java_client/ios/IOSTouchAction.java +++ b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java @@ -1,24 +1,30 @@ package io.appium.java_client.ios; -import io.appium.java_client.MobileDriver; +import io.appium.java_client.CreatesSwipeAction; +import io.appium.java_client.PerformsTouchActions; import io.appium.java_client.TouchAction; -import io.appium.java_client.TouchableElement; +import org.openqa.selenium.WebElement; -public class IOSTouchAction extends TouchAction { +public class IOSTouchAction extends TouchAction implements CreatesSwipeAction { - public IOSTouchAction(MobileDriver driver) { - super(driver); + public IOSTouchAction(PerformsTouchActions performsTouchActions) { + super(performsTouchActions); } - /** - * @see TouchableElement#swipe(int, int, int, int, int). - */ - @Deprecated protected TouchAction swipe(int startx, int starty, int endx, int endy, int duration) { - int endX = endx - startx; - int endY = endy - starty; + public TouchAction swipe(int startX, int startY, int endX, int endY, int duration) { + int xOffset = endX - startX; + int yOffset = endY - startX; + return press(startX, startY).waitAction(duration).moveTo(xOffset, yOffset).release(); + } + + @Override + public TouchAction swipe(int startX, int startY, WebElement element, int duration) { + return press(startX, startY).waitAction(duration).moveTo(element).release(); + } - // appium converts press-wait-moveto-release to a swipe action - return press(startx, starty).waitAction(duration).moveTo(endX, endY).release(); + @Override + public TouchAction swipe(WebElement element1, WebElement element2, int duration) { + return press(element1).waitAction(duration).moveTo(element2).release(); } } From f799d341cf2023b0a28809460c71fb489f8912dd Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Thu, 10 Nov 2016 13:59:00 +0300 Subject: [PATCH 08/20] #456 FIX #454 FIX: AndroidTouchActions were covered with tests. - also code issues were got fixed --- .../appium/java_client/MultiTouchAction.java | 12 +-- .../java_client/PerformsTouchActions.java | 4 +- .../io/appium/java_client/TouchAction.java | 11 +-- .../java_client/android/AndroidDriver.java | 4 +- .../bys/builder/AppiumByBuilder.java | 5 +- .../service/local/AppiumServiceBuilder.java | 3 +- .../android/AndroidGestureTest.java | 31 ------- .../android/AndroidSwipeGestureTest.java | 84 +++++++++++++++++++ .../java_client/ios/IOSGesturesTest.java | 8 +- .../pagefactory_tests/IOSPageFactoryTest.java | 2 +- .../SelendroidCombinedWidgetTest.java | 2 +- 11 files changed, 105 insertions(+), 61 deletions(-) create mode 100644 src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java diff --git a/src/main/java/io/appium/java_client/MultiTouchAction.java b/src/main/java/io/appium/java_client/MultiTouchAction.java index f6af39b2f..c44160a37 100644 --- a/src/main/java/io/appium/java_client/MultiTouchAction.java +++ b/src/main/java/io/appium/java_client/MultiTouchAction.java @@ -41,7 +41,6 @@ * Calling perform() sends the action command to the Mobile Driver. Otherwise, more and * more actions can be chained. */ -@SuppressWarnings({"rawtypes", "unchecked"}) public class MultiTouchAction { private ImmutableList.Builder actions; @@ -60,7 +59,6 @@ public MultiTouchAction(PerformsTouchActions performsTouchActions) { */ public MultiTouchAction add(TouchAction action) { actions.add(action); - return this; } @@ -82,13 +80,13 @@ public void perform() { } - protected ImmutableMap getParameters() { + protected ImmutableMap> getParameters() { ImmutableList.Builder listOfActionChains = ImmutableList.builder(); ImmutableList touchActions = actions.build(); - for (TouchAction action : touchActions) { + touchActions.forEach(action -> { listOfActionChains.add(action.getParameters().get("actions")); - } + }); return ImmutableMap.of("actions", listOfActionChains.build()); } @@ -115,7 +113,6 @@ public MultiTouchAction pinch(WebElement el) { /** * Creates few combined touch actions which performs the pinching by given coordinates and offsets. - * * @param x is a x-coordinate to perform the pinching to * @param y is an y-coordinate to perform the pinching to * @param xOffset is an +/- offset from the given x-coordinate to perform the pinching to @@ -134,7 +131,6 @@ public MultiTouchAction pinch(int x, int y, int xOffset, int yOffset) { /** * Creates few combined touch actions which performs the vertical pinching by given coordinates and y-Offset. - * * @param x is a x-coordinate to perform the pinching to * @param y is an y-coordinate to perform the pinching to * @param yOffset is an +/- offset from the given y-coordinate to perform the pinching to @@ -165,7 +161,6 @@ public MultiTouchAction zoom(WebElement el) { /** * Creates few combined touch actions which performs the zooming by given coordinates and x/y-Offset value. - * * @param x is a x-coordinate to perform the zooming from * @param y is a y-coordinate to perform the zooming from * @param xOffset is an +/- offset from the given x-coordinate to perform the zooming from @@ -183,7 +178,6 @@ public MultiTouchAction zoom(int x, int y, int xOffset, int yOffset) { /** * Creates few combined touch actions which performs the vertical zooming by given coordinates and x/y-Offset value. - * * @param x is a x-coordinate to perform the zooming from * @param y is a y-coordinate to perform the zooming from * @param yOffset is an +/- offset from the given y-coordinate to perform the zooming from diff --git a/src/main/java/io/appium/java_client/PerformsTouchActions.java b/src/main/java/io/appium/java_client/PerformsTouchActions.java index 123811b2c..0a3056730 100644 --- a/src/main/java/io/appium/java_client/PerformsTouchActions.java +++ b/src/main/java/io/appium/java_client/PerformsTouchActions.java @@ -35,7 +35,7 @@ public interface PerformsTouchActions extends ExecutesMethod { * @return the same touch action object */ default TouchAction performTouchAction(TouchAction touchAction) { - ImmutableMap parameters = touchAction.getParameters(); + ImmutableMap> parameters = touchAction.getParameters(); execute(PERFORM_TOUCH_ACTION, parameters); return touchAction; } @@ -50,7 +50,7 @@ default TouchAction performTouchAction(TouchAction touchAction) { * @param multiAction the MultiTouchAction object to perform. */ default void performMultiTouchAction(MultiTouchAction multiAction) { - ImmutableMap parameters = multiAction.getParameters(); + ImmutableMap> parameters = multiAction.getParameters(); execute(PERFORM_MULTI_TOUCH, parameters); } } diff --git a/src/main/java/io/appium/java_client/TouchAction.java b/src/main/java/io/appium/java_client/TouchAction.java index 58e547103..00a9b6ea8 100644 --- a/src/main/java/io/appium/java_client/TouchAction.java +++ b/src/main/java/io/appium/java_client/TouchAction.java @@ -22,7 +22,6 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.internal.HasIdentity; - /** * Used for Webdriver 3 touch actions * See the Webriver 3 spec @@ -33,7 +32,6 @@ * Calling perform() sends the action command to the Mobile Driver. Otherwise, * more and more actions can be chained. */ -@SuppressWarnings({"rawtypes", "unchecked"}) public class TouchAction { private ImmutableList.Builder parameterBuilder; @@ -330,13 +328,12 @@ public TouchAction perform() { * * @return A map of parameters for this touch action to pass as part of mjsonwp. */ - protected ImmutableMap getParameters() { + protected ImmutableMap> getParameters() { - ImmutableList.Builder parameters = ImmutableList.builder(); + ImmutableList.Builder parameters = ImmutableList.builder(); ImmutableList actionList = parameterBuilder.build(); - for (ActionParameter action : actionList) { - parameters.add(action.getParameterMap()); - } + + actionList.forEach(action -> {parameters.add(action.getParameterMap());}); return ImmutableMap.of("actions", parameters.build()); } diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 9a188c132..2ccae1c34 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -161,9 +161,7 @@ public AndroidDriver(Capabilities desiredCapabilities) { JsonToAndroidElementConverter.class); } - /** - * @see io.appium.java_client.TouchableElement#swipe(int, int, int, int, int) - */ + @Override public void swipe(int startx, int starty, int endx, int endy, int duration) { AndroidTouchAction touchaction = new AndroidTouchAction(this); diff --git a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java index 1b9aa7a59..2f6d8e746 100644 --- a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java +++ b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java @@ -119,7 +119,6 @@ private static By getMobileBy(Annotation annotation, String valueName) { + valueName); } - @SuppressWarnings("unchecked") private static T getComplexMobileBy(Annotation[] annotations, Class requiredByClass) { By[] byArray = new By[annotations.length]; @@ -127,9 +126,9 @@ private static T getComplexMobileBy(Annotation[] annotations, byArray[i] = getMobileBy(annotations[i], getFilledValue(annotations[i])); } try { - Constructor c = requiredByClass.getConstructor(By[].class); + Constructor c = requiredByClass.getConstructor(By[].class); Object[] values = new Object[] {byArray}; - return (T) c.newInstance(values); + return c.newInstance(values); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java index fb51b497d..c168907d2 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java @@ -372,8 +372,7 @@ private String parseCapabilitiesIfUNIX() { return "{" + result + "}"; } - - @SuppressWarnings("unchecked") + private String parseCapabilities() { if (Platform.getCurrent().is(Platform.WINDOWS)) { return parseCapabilitiesIfWindows(); 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 dcc6ca822..ce393fd55 100644 --- a/src/test/java/io/appium/java_client/android/AndroidGestureTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidGestureTest.java @@ -22,7 +22,6 @@ import io.appium.java_client.MobileBy; 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 org.junit.Test; import org.openqa.selenium.By; @@ -108,34 +107,4 @@ public class AndroidGestureTest extends BaseAndroidTest { assertEquals("OFF" ,driver .findElementById("io.appium.android.apis:id/button_toggle").getText()); } - - @Test public void verticalSwipingTest() throws Exception { - driver.findElementByAccessibilityId("Views").click(); - AndroidElement listView = driver.findElementByClassName("android.widget.ListView"); - MobileElement textView = driver.findElementById("android:id/text1"); - - String originalText = textView.getText(); - - listView.swipe(SwipeElementDirection.UP, 20, 15, 1000); - assertNotEquals(originalText, textView.getText()); - - listView.swipe(SwipeElementDirection.DOWN, 20, 15, 1000); - assertEquals(originalText, textView.getText()); - } - - @Test public void horizontalSwipingTest() throws Exception { - driver.startActivity("io.appium.android.apis", ".view.Gallery1"); - - AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery"); - int originalImageCount = gallery - .findElementsByClassName("android.widget.ImageView").size(); - - gallery.swipe(SwipeElementDirection.LEFT, 5, 5, 2000); - assertNotEquals(originalImageCount, gallery - .findElementsByClassName("android.widget.ImageView").size()); - - gallery.swipe(SwipeElementDirection.RIGHT, 5, 5, 2000); - assertEquals(originalImageCount, gallery - .findElementsByClassName("android.widget.ImageView").size()); - } } diff --git a/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java new file mode 100644 index 000000000..7b3f4550a --- /dev/null +++ b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java @@ -0,0 +1,84 @@ +package io.appium.java_client.android; + +import io.appium.java_client.MobileElement; +import io.appium.java_client.SwipeElementDirection; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Point; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class AndroidSwipeGestureTest extends BaseAndroidTest { + + @Before + public void setUp() throws Exception { + driver.resetApp(); + } + + @Test + public void verticalSwipingTest() throws Exception { + driver.findElementByAccessibilityId("Views").click(); + AndroidElement listView = driver.findElementByClassName("android.widget.ListView"); + MobileElement textView = driver.findElementById("android:id/text1"); + + String originalText = textView.getText(); + + AndroidTouchAction touchAction = new AndroidTouchAction(driver); + touchAction.swipe(listView, SwipeElementDirection.UP, 20, 15, 1000).perform(); + assertNotEquals(originalText, textView.getText()); + + AndroidTouchAction touchAction2 = new AndroidTouchAction(driver); + touchAction2.swipe(listView, SwipeElementDirection.DOWN, 20, 15, 1000).perform(); + + Thread.sleep(5000); + assertEquals(originalText, textView.getText()); + } + + @Test public void horizontalSwipingTest() throws Exception { + driver.startActivity("io.appium.android.apis", ".view.Gallery1"); + + AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery"); + int originalImageCount = gallery + .findElementsByClassName("android.widget.ImageView").size(); + + AndroidTouchAction touchAction = new AndroidTouchAction(driver); + touchAction.swipe(gallery, SwipeElementDirection.LEFT, 5, 5, 2000).perform(); + assertNotEquals(originalImageCount, gallery + .findElementsByClassName("android.widget.ImageView").size()); + + AndroidTouchAction touchAction2 = new AndroidTouchAction(driver); + touchAction2.swipe(gallery, SwipeElementDirection.RIGHT, 5, 5, 2000).perform(); + assertEquals(originalImageCount, gallery + .findElementsByClassName("android.widget.ImageView").size()); + } + + @Test public void swipeFromElementToElement() { + driver.findElementByAccessibilityId("Views").click(); + + AndroidElement e1 = driver.findElementByAccessibilityId("Chronometer"); + AndroidElement e2 = driver.findElementByAccessibilityId("Focus"); + + Point originalLocation = e2.getLocation(); + AndroidTouchAction touchAction = new AndroidTouchAction(driver); + touchAction.swipe(e2, e1, 2000).perform(); + + Point newLocation = e2.getLocation(); + assertNotEquals(originalLocation, newLocation); + } + + @Test public void swipeFromCoordinatesToElement() { + driver.findElementByAccessibilityId("Views").click(); + + AndroidElement e1 = driver.findElementByAccessibilityId("Chronometer"); + AndroidElement e2 = driver.findElementByAccessibilityId("Focus"); + + Point originalLocation = e2.getLocation(); + AndroidTouchAction touchAction = new AndroidTouchAction(driver); + touchAction.swipe(originalLocation.x + 50, originalLocation.y, e1, 2000).perform(); + + Point newLocation = e2.getLocation(); + assertNotEquals(originalLocation, newLocation); + } + +} diff --git a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java index 4e9914beb..1ff5ce0c0 100644 --- a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java @@ -47,9 +47,13 @@ public class IOSGesturesTest extends BaseIOSTest { @Test public void horizontalSwipingTest() { MobileElement slider = driver.findElementByClassName("UIASlider"); - slider.swipe(SwipeElementDirection.LEFT, slider.getSize().getWidth() / 2, 0, 3000); + + IOSTouchAction touchAction = new IOSTouchAction(driver); + touchAction.swipe(slider, SwipeElementDirection.LEFT, slider.getSize().getWidth() / 2, 0, 3000); assertEquals("1%", slider.getAttribute("value")); - slider.swipe(SwipeElementDirection.RIGHT, 2, 0, 3000); + + IOSTouchAction touchAction2 = new IOSTouchAction(driver); + touchAction2.swipe(slider, SwipeElementDirection.RIGHT, 2, 0, 3000); assertEquals("100%", slider.getAttribute("value")); } } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java index 6b6965785..df269a4fe 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java @@ -163,7 +163,7 @@ public class IOSPageFactoryTest { //sometimes environment has performance problems capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver(service.getUrl(), capabilities); + driver = new IOSDriver<>(service.getUrl(), capabilities); } /** diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java index 6b72e4983..f381960e3 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit; public class SelendroidCombinedWidgetTest implements WidgetTest { - private static int SELENDROID_PORT = 9999; + private static AppiumDriverLocalService service; private AndroidDriver driver; private RottenTomatoesAppWithCombinedWidgets rottenTomatoes; From f07ac6ee8ace57f5b5908481552787cc1f25b8ca Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Thu, 10 Nov 2016 15:18:50 +0300 Subject: [PATCH 09/20] #456 FIX #454 FIX: Refactoring of MobileElement --- .../java/io/appium/java_client/MobileElement.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 1671c71ea..5bbba05a5 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -43,15 +43,21 @@ public Point getCenter() { } @Override public void tap(int fingers, int duration) { - ((AppiumDriver) parent).tap(fingers, this, duration); + MultiTouchAction tap = + new MultiTouchAction(PerformsTouchActions.class.cast(parent)); + tap.tap(fingers, this, duration).perform(); } @Override public void pinch() { - ((AppiumDriver) parent).pinch(this); + MultiTouchAction pinch = new MultiTouchAction( + PerformsTouchActions.class.cast(parent)); + pinch.pinch(this).perform(); } @Override public void zoom() { - ((AppiumDriver) parent).zoom(this); + MultiTouchAction zoom = new MultiTouchAction( + PerformsTouchActions.class.cast(parent)); + zoom.zoom(this).perform(); } @Deprecated From 980b6a1204c0f60d72c9e1491670f9f7b6bb0d12 Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Fri, 11 Nov 2016 16:46:06 +0300 Subject: [PATCH 10/20] #456 FIX #454 FIX: IOSGesturesTest was redesigned. - IOSSwipeGestureTest was added --- .../io/appium/java_client/MobileElement.java | 12 +++++----- .../java_client/ios/IOSElementTest.java | 2 +- .../java_client/ios/IOSGesturesTest.java | 13 ----------- .../java_client/ios/IOSSwipeGestureTest.java | 22 +++++++++++++++++++ 4 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 5bbba05a5..4cdb7e208 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -43,21 +43,21 @@ public Point getCenter() { } @Override public void tap(int fingers, int duration) { - MultiTouchAction tap = + MultiTouchAction tapMultiTouchAction = new MultiTouchAction(PerformsTouchActions.class.cast(parent)); - tap.tap(fingers, this, duration).perform(); + tapMultiTouchAction.tap(fingers, this, duration).perform(); } @Override public void pinch() { - MultiTouchAction pinch = new MultiTouchAction( + MultiTouchAction pinchMultiTouchAction = new MultiTouchAction( PerformsTouchActions.class.cast(parent)); - pinch.pinch(this).perform(); + pinchMultiTouchAction.pinch(this).perform(); } @Override public void zoom() { - MultiTouchAction zoom = new MultiTouchAction( + MultiTouchAction zoomMultiTouchAction = new MultiTouchAction( PerformsTouchActions.class.cast(parent)); - zoom.zoom(this).perform(); + zoomMultiTouchAction.zoom(this).perform(); } @Deprecated diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/test/java/io/appium/java_client/ios/IOSElementTest.java index fc465395a..5eaf52a0b 100644 --- a/src/test/java/io/appium/java_client/ios/IOSElementTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSElementTest.java @@ -34,7 +34,7 @@ public class IOSElementTest extends BaseIOSTest { .findElementByIosUIAutomation(".elements().withName(\"Answer\")").getText(), null); } - @Test public void setValueNunslaughterTest() { + @Test public void setValuerTest() { IOSElement slider = (IOSElement) driver.findElementByClassName("UIASlider"); slider.setValue("0%"); assertEquals("0%", slider.getAttribute("value")); diff --git a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java index 1ff5ce0c0..b9eaed867 100644 --- a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java @@ -20,7 +20,6 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.MultiTouchAction; -import io.appium.java_client.SwipeElementDirection; import org.junit.Test; public class IOSGesturesTest extends BaseIOSTest { @@ -44,17 +43,5 @@ public class IOSGesturesTest extends BaseIOSTest { MobileElement e = driver.findElementById("IntegerA"); new MultiTouchAction(driver).pinch(e).perform(); } - - @Test public void horizontalSwipingTest() { - MobileElement slider = driver.findElementByClassName("UIASlider"); - - IOSTouchAction touchAction = new IOSTouchAction(driver); - touchAction.swipe(slider, SwipeElementDirection.LEFT, slider.getSize().getWidth() / 2, 0, 3000); - assertEquals("1%", slider.getAttribute("value")); - - IOSTouchAction touchAction2 = new IOSTouchAction(driver); - touchAction2.swipe(slider, SwipeElementDirection.RIGHT, 2, 0, 3000); - assertEquals("100%", slider.getAttribute("value")); - } } diff --git a/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java new file mode 100644 index 000000000..008bfa36b --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java @@ -0,0 +1,22 @@ +package io.appium.java_client.ios; + +import io.appium.java_client.MobileElement; +import io.appium.java_client.SwipeElementDirection; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class IOSSwipeGestureTest extends BaseIOSTest { + @Test + public void horizontalSwipingTest() { + MobileElement slider = driver.findElementByClassName("UIASlider"); + + IOSTouchAction touchAction = new IOSTouchAction(driver); + touchAction.swipe(slider, SwipeElementDirection.LEFT, slider.getSize().getWidth() / 2, 0, 3000); + assertEquals("1%", slider.getAttribute("value")); + + IOSTouchAction touchAction2 = new IOSTouchAction(driver); + touchAction2.swipe(slider, SwipeElementDirection.RIGHT, 2, 0, 3000); + assertEquals("100%", slider.getAttribute("value")); + } +} From d832a19bc83ec7a8787bc3df3894af5010265f57 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Sat, 12 Nov 2016 00:27:00 +0300 Subject: [PATCH 11/20] #456 FIX #454 FIX: Checkstyle issues were got fixed --- .../io/appium/java_client/AppiumDriver.java | 17 +++++++++-------- .../appium/java_client/CreatesSwipeAction.java | 2 +- .../java_client/SwipeElementDirection.java | 11 +++++++++++ .../java/io/appium/java_client/TouchAction.java | 2 +- .../android/AndroidMobileCommandHelper.java | 9 +++++---- .../appium/java_client/ios/IOSTouchAction.java | 1 + .../io/appium/java_client/ios/ShakesDevice.java | 4 ++-- .../android/AndroidSwipeGestureTest.java | 6 +++--- .../appium/java_client/ios/IOSGesturesTest.java | 5 ++--- .../java_client/ios/IOSSwipeGestureTest.java | 4 ++-- .../java_client/ios/XCUIAutomationTest.java | 4 ++-- 11 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 906064efc..96d17c609 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -211,11 +211,11 @@ public List findElementsByXPath(String using) { return executeMethod; } - @Deprecated /** * This method is deprecated and it is going to be removed soon. * Please use {@link MultiTouchAction#tap(int, WebElement, int)}. */ + @Deprecated public void tap(int fingers, WebElement element, int duration) { MultiTouchAction multiTouch = new MultiTouchAction(this); @@ -226,11 +226,11 @@ public void tap(int fingers, WebElement element, int duration) { multiTouch.perform(); } - @Deprecated /** * This method is deprecated and it is going to be removed soon. * Please use {@link MultiTouchAction#tap(int, int, int, int)}. */ + @Deprecated public void tap(int fingers, int x, int y, int duration) { MultiTouchAction multiTouch = new MultiTouchAction(this); @@ -240,31 +240,32 @@ public void tap(int fingers, int x, int y, int duration) { multiTouch.perform(); } - @Deprecated /** - * This method is deprecated due to it was moved to {@link TouchAction#} + * This method is deprecated. + * It was moved to {@link CreatesSwipeAction#swipe(int, int, int, int, int)}. */ + @Deprecated public void swipe(int startx, int starty, int endx, int endy, int duration) { } - @Deprecated /** * This method is deprecated and it is going to be removed soon. * Please use {@link MultiTouchAction#pinch(WebElement)}. */ + @Deprecated public void pinch(WebElement el) { MultiTouchAction multiTouch = new MultiTouchAction(this); multiTouch.pinch(el).perform(); } - @Deprecated /** * This method is deprecated and it is going to be removed soon. * Please use {@link MultiTouchAction#pinch(int, int, int, int)} or * {@link MultiTouchAction#pinch(int, int, int)} */ + @Deprecated public void pinch(int x, int y) { MultiTouchAction multiTouch = new MultiTouchAction(this); @@ -283,23 +284,23 @@ public void pinch(int x, int y) { multiTouch.add(action0).add(action1).perform(); } - @Deprecated /** * This method is deprecated and it is going to be removed soon. * Please use {@link MultiTouchAction#zoom(WebElement)}. */ + @Deprecated public void zoom(WebElement el) { MultiTouchAction multiTouch = new MultiTouchAction(this); multiTouch.zoom(el).perform(); } - @Deprecated /** * This method is deprecated and it is going to be removed soon. * Please use {@link MultiTouchAction#zoom(int, int, int, int)} or * {@link MultiTouchAction#zoom(int, int, int)}. */ + @Deprecated public void zoom(int x, int y) { MultiTouchAction multiTouch = new MultiTouchAction(this); diff --git a/src/main/java/io/appium/java_client/CreatesSwipeAction.java b/src/main/java/io/appium/java_client/CreatesSwipeAction.java index 856d2d095..2f821e285 100644 --- a/src/main/java/io/appium/java_client/CreatesSwipeAction.java +++ b/src/main/java/io/appium/java_client/CreatesSwipeAction.java @@ -46,7 +46,7 @@ public interface CreatesSwipeAction { /** * Creates combined touch action for the swiping from one element to another. * - * @param element2 an element to swipe to + * @param element1 an element to swipe to * @param element2 an element to swipe to * @param duration in milliseconds * @return an instance of combined {@link TouchAction} diff --git a/src/main/java/io/appium/java_client/SwipeElementDirection.java b/src/main/java/io/appium/java_client/SwipeElementDirection.java index 5098ad0de..15cd87a7e 100644 --- a/src/main/java/io/appium/java_client/SwipeElementDirection.java +++ b/src/main/java/io/appium/java_client/SwipeElementDirection.java @@ -185,6 +185,17 @@ static void checkXCoordinate(int x, Point location, Dimension size, int offSet) abstract void checkDirection(int x1, int y1, int x2, int y2); + /** + * Creates the swiping action. It is supposed to be performed inside the given element. + * + * @param createsSwipeAction an instance that implements {@link CreatesSwipeAction} + * @param element the element that is going to be swiped + * @param offset1 from the first (starting) element board + * @param offset2 from the ending element board + * @param duration in milliseconds + * @return an instance of {@link TouchAction} + * @throws IllegalCoordinatesException when starting/ending coordinates are outside of the given element + */ public TouchAction swipe(CreatesSwipeAction createsSwipeAction, MobileElement element, int offset1, int offset2, int duration) throws IllegalCoordinatesException { Point p = element.getCenter(); diff --git a/src/main/java/io/appium/java_client/TouchAction.java b/src/main/java/io/appium/java_client/TouchAction.java index 00a9b6ea8..9666f9204 100644 --- a/src/main/java/io/appium/java_client/TouchAction.java +++ b/src/main/java/io/appium/java_client/TouchAction.java @@ -333,7 +333,7 @@ protected ImmutableMap> getParameters() { ImmutableList.Builder parameters = ImmutableList.builder(); ImmutableList actionList = parameterBuilder.build(); - actionList.forEach(action -> {parameters.add(action.getParameterMap());}); + actionList.forEach(action -> parameters.add(action.getParameterMap())); return ImmutableMap.of("actions", parameters.build()); } diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java index 245dba633..450965707 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -87,19 +87,20 @@ public class AndroidMobileCommandHelper extends MobileCommand { IS_LOCKED, ImmutableMap.of()); } - @Deprecated + /** * It is deprecated. Please use {@link MobileCommand#pressKeyCodeCommand(int)} instead. */ + @Deprecated public static Map.Entry> pressKeyCodeCommand(int key) { return new AbstractMap.SimpleEntry<>( PRESS_KEY_CODE, prepareArguments("keycode", key)); } - @Deprecated /** * It is deprecated. Please use {@link MobileCommand#pressKeyCodeCommand(int, Integer)} instead. */ + @Deprecated public static Map.Entry> pressKeyCodeCommand(int key, Integer metastate) { String[] parameters = new String[] {"keycode", "metastate"}; @@ -108,19 +109,19 @@ public class AndroidMobileCommandHelper extends MobileCommand { PRESS_KEY_CODE, prepareArguments(parameters, values)); } - @Deprecated /** * It is deprecated. Please use {@link MobileCommand#longPressKeyCodeCommand(int)} instead. */ + @Deprecated public static Map.Entry> longPressKeyCodeCommand(int key) { return new AbstractMap.SimpleEntry<>( LONG_PRESS_KEY_CODE, prepareArguments("keycode", key)); } - @Deprecated /** * It is deprecated. Please use {@link MobileCommand#longPressKeyCodeCommand(int, Integer)} instead. */ + @Deprecated public static Map.Entry> longPressKeyCodeCommand(int key, Integer metastate) { String[] parameters = new String[] {"keycode", "metastate"}; diff --git a/src/main/java/io/appium/java_client/ios/IOSTouchAction.java b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java index c599c3101..fd841c427 100644 --- a/src/main/java/io/appium/java_client/ios/IOSTouchAction.java +++ b/src/main/java/io/appium/java_client/ios/IOSTouchAction.java @@ -12,6 +12,7 @@ public IOSTouchAction(PerformsTouchActions performsTouchActions) { super(performsTouchActions); } + @Override public TouchAction swipe(int startX, int startY, int endX, int endY, int duration) { int xOffset = endX - startX; int yOffset = endY - startX; diff --git a/src/main/java/io/appium/java_client/ios/ShakesDevice.java b/src/main/java/io/appium/java_client/ios/ShakesDevice.java index abd601852..208f05bb1 100644 --- a/src/main/java/io/appium/java_client/ios/ShakesDevice.java +++ b/src/main/java/io/appium/java_client/ios/ShakesDevice.java @@ -16,11 +16,11 @@ package io.appium.java_client.ios; +import static io.appium.java_client.ios.IOSMobileCommandHelper.shakeCommand; + import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; -import static io.appium.java_client.ios.IOSMobileCommandHelper.shakeCommand; - public interface ShakesDevice extends ExecutesMethod { /** diff --git a/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java index 7b3f4550a..4839780b7 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java @@ -1,14 +1,14 @@ package io.appium.java_client.android; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + import io.appium.java_client.MobileElement; import io.appium.java_client.SwipeElementDirection; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.Point; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - public class AndroidSwipeGestureTest extends BaseAndroidTest { @Before diff --git a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java index b9eaed867..39b8fa1bd 100644 --- a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java @@ -24,10 +24,9 @@ public class IOSGesturesTest extends BaseIOSTest { - @Test public void tapTest() { - driver.findElementById("IntegerA").sendKeys("2"); - driver.findElementById("IntegerB").sendKeys("4"); + driver.findElementById("IntegerA").sendKeys("2"); + driver.findElementById("IntegerB").sendKeys("4"); MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); new MultiTouchAction(driver).tap(2, e, 2000).perform(); diff --git a/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java index 008bfa36b..bad1ecb88 100644 --- a/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java @@ -1,11 +1,11 @@ package io.appium.java_client.ios; +import static org.junit.Assert.assertEquals; + import io.appium.java_client.MobileElement; import io.appium.java_client.SwipeElementDirection; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class IOSSwipeGestureTest extends BaseIOSTest { @Test public void horizontalSwipingTest() { diff --git a/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java b/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java index b9ca62722..fa448c383 100644 --- a/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java +++ b/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java @@ -16,6 +16,8 @@ package io.appium.java_client.ios; +import static org.junit.Assert.assertEquals; + import io.appium.java_client.MobileElement; import io.appium.java_client.remote.AutomationName; import io.appium.java_client.remote.IOSMobileCapabilityType; @@ -31,8 +33,6 @@ import java.io.File; -import static org.junit.Assert.assertEquals; - public class XCUIAutomationTest { protected static IOSDriver driver; From f8ad4555a5627bd0a8a995b50572cc4818138a5a Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Sat, 12 Nov 2016 17:41:54 +0300 Subject: [PATCH 12/20] #456 FIX #454 FIX: The additional test on Android. - the swiping combined with the tapping. --- .../android/AndroidSwipeGestureTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java index 4839780b7..a085dd24c 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java @@ -1,12 +1,16 @@ package io.appium.java_client.android; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThat; import io.appium.java_client.MobileElement; +import io.appium.java_client.MultiTouchAction; import io.appium.java_client.SwipeElementDirection; import org.junit.Before; import org.junit.Test; +import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; public class AndroidSwipeGestureTest extends BaseAndroidTest { @@ -81,4 +85,17 @@ public void verticalSwipingTest() throws Exception { assertNotEquals(originalLocation, newLocation); } + @Test public void whenSwipingIsCombinedWithOtherActions() { + driver.findElementByAccessibilityId("Views").click(); + + AndroidElement chronometer = driver.findElementByAccessibilityId("Chronometer"); + AndroidElement focus = driver.findElementByAccessibilityId("Focus"); + + AndroidTouchAction touchAction = new AndroidTouchAction(driver); + touchAction.swipe(focus, chronometer, 2000) + .tap(driver.findElementByAccessibilityId("Gallery")).perform(); + + assertThat(driver.findElementsByClassName("android.widget.TextView").size(), is(3)); + } + } From 2ba3652e07b7871dc3413d86035ce4fffde6b7cd Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Sun, 13 Nov 2016 22:30:47 +0300 Subject: [PATCH 13/20] Issues that found by codecy were got fixed --- src/main/java/io/appium/java_client/AppiumDriver.java | 2 +- .../io/appium/java_client/android/AndroidSwipeGestureTest.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 96d17c609..bf2d412b9 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -246,7 +246,7 @@ public void tap(int fingers, int x, int y, int duration) { */ @Deprecated public void swipe(int startx, int starty, int endx, int endy, int duration) { - + //does nothing } /** diff --git a/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java index a085dd24c..e5dbc34c9 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSwipeGestureTest.java @@ -6,11 +6,9 @@ import static org.junit.Assert.assertThat; import io.appium.java_client.MobileElement; -import io.appium.java_client.MultiTouchAction; import io.appium.java_client.SwipeElementDirection; import org.junit.Before; import org.junit.Test; -import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; public class AndroidSwipeGestureTest extends BaseAndroidTest { From f9a928e48028a699bf4d00f452ace9ffd32b07da Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Wed, 16 Nov 2016 22:36:55 +0530 Subject: [PATCH 14/20] The addition #513 Fixed Codacy errors Fixed Codacy errors --- .../ios/IOSScrollingSearchingTest.java | 4 +- .../java_client/ios/IOSSwipeGestureTest.java | 121 +++++++++++++++++- 2 files changed, 122 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java b/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java index 05824852f..0e55343b9 100644 --- a/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java @@ -23,6 +23,7 @@ import io.appium.java_client.remote.IOSMobileCapabilityType; import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -41,7 +42,8 @@ public static void beforeClass() throws Exception { service.start(); if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); + throw new AppiumServerHasNotBeenStartedLocallyException( + "An appium server node is not started!"); } File appDir = new File("src/test/java/io/appium/java_client"); diff --git a/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java index bad1ecb88..1df98a42a 100644 --- a/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java @@ -1,15 +1,72 @@ package io.appium.java_client.ios; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import io.appium.java_client.MobileElement; import io.appium.java_client.SwipeElementDirection; +import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; +import org.openqa.selenium.Point; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.io.File; + +public class IOSSwipeGestureTest { + + private static AppiumDriverLocalService service; + protected static IOSDriver driver; + + @BeforeClass + public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException( + "An appium server node is not started!"); + } + + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "UICatalog.app.zip"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + //sometimes environment has performance problems + capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new IOSDriver<>(service.getUrl(), capabilities); + } + + /** + * finishing. + */ + @AfterClass + public static void afterClass() { + if (driver != null) { + driver.quit(); + } + if (service != null) { + service.stop(); + } + } + + @After public void afterMethod() { + driver.resetApp(); + } -public class IOSSwipeGestureTest extends BaseIOSTest { @Test public void horizontalSwipingTest() { - MobileElement slider = driver.findElementByClassName("UIASlider"); + driver.findElementByAccessibilityId("Sliders").click(); + MobileElement slider = driver.findElementsByClassName("UIASlider").get(2); IOSTouchAction touchAction = new IOSTouchAction(driver); touchAction.swipe(slider, SwipeElementDirection.LEFT, slider.getSize().getWidth() / 2, 0, 3000); @@ -19,4 +76,64 @@ public void horizontalSwipingTest() { touchAction2.swipe(slider, SwipeElementDirection.RIGHT, 2, 0, 3000); assertEquals("100%", slider.getAttribute("value")); } + + @Test + public void verticalSwipingTest() throws InterruptedException { + IOSElement tableView = (IOSElement) driver.findElementByClassName("UIATableView"); + MobileElement element = driver.findElementByAccessibilityId("UIAStaticText"); + + String originalText = element.getText(); + + IOSTouchAction touchAction = new IOSTouchAction(driver); + touchAction.swipe(tableView, SwipeElementDirection.UP, 20, 15, 3000); + assertNotEquals(originalText, element.getText()); + + IOSTouchAction touchAction2 = new IOSTouchAction(driver); + touchAction2.swipe(tableView, SwipeElementDirection.DOWN, 20, 15, 3000); + + Thread.sleep(5000); + assertEquals(originalText, element.getText()); + } + + @Test + public void swipeFromElementToElement() { + IOSElement e1 = (IOSElement) driver.findElementsByClassName("UIAWindow").get(1) + .findElementByAccessibilityId("Buttons"); + IOSElement e2 = (IOSElement) driver.findElementsByClassName("UIAWindow").get(1) + .findElementByAccessibilityId("Sliders"); + + Point originalLocation = e2.getLocation(); + IOSTouchAction touchAction = new IOSTouchAction(driver); + touchAction.swipe(e2, e1, 3000).perform(); + + Point newLocation = e2.getLocation(); + assertNotEquals(originalLocation, newLocation); + } + + @Test public void swipeFromCoordinatesToElement() { + IOSElement e1 = (IOSElement) driver.findElementsByClassName("UIAWindow").get(1) + .findElementByAccessibilityId("Buttons"); + IOSElement e2 = (IOSElement) driver.findElementsByClassName("UIAWindow").get(1) + .findElementByAccessibilityId("Sliders"); + + Point originalLocation = e2.getLocation(); + IOSTouchAction touchAction = new IOSTouchAction(driver); + touchAction.swipe(originalLocation.x + 50, originalLocation.y, e1, 3000).perform(); + + Point newLocation = e2.getLocation(); + assertNotEquals(originalLocation, newLocation); + } + + @Test public void whenSwipingIsCombinedWithOtherActions() { + IOSElement e1 = (IOSElement) driver.findElementsByClassName("UIAWindow").get(1) + .findElementByAccessibilityId("Buttons"); + IOSElement e2 = (IOSElement) driver.findElementsByClassName("UIAWindow").get(1) + .findElementByAccessibilityId("Sliders"); + + IOSTouchAction touchAction = new IOSTouchAction(driver); + touchAction.swipe(e2, e1, 3000) + .tap(driver.findElementByAccessibilityId("Switches")).perform(); + + assertTrue(driver.findElementByAccessibilityId("TINTED").isDisplayed()); + } } From 9ae86062967a0830761c8d4e2cb68de8192c5a54 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 20 Nov 2016 01:19:19 +0530 Subject: [PATCH 15/20] Added isKeyboardShown,getDisplayDensity and getSystemBars Commands --- .../appium/java_client/HasDeviceDetails.java | 21 +++++++++++ .../io/appium/java_client/MobileCommand.java | 6 +++ .../java_client/android/AndroidDriver.java | 4 +- .../android/AndroidMobileCommandHelper.java | 36 ++++++++++++++++++ .../java_client/android/IsKeyboardShown.java | 17 +++++++++ .../android/AndroidSearchingTest.java | 37 ++----------------- .../java_client/android/BaseAndroidTest.java | 11 ++---- 7 files changed, 89 insertions(+), 43 deletions(-) create mode 100644 src/main/java/io/appium/java_client/HasDeviceDetails.java create mode 100644 src/main/java/io/appium/java_client/android/IsKeyboardShown.java diff --git a/src/main/java/io/appium/java_client/HasDeviceDetails.java b/src/main/java/io/appium/java_client/HasDeviceDetails.java new file mode 100644 index 000000000..7a36e9591 --- /dev/null +++ b/src/main/java/io/appium/java_client/HasDeviceDetails.java @@ -0,0 +1,21 @@ +package io.appium.java_client; + + +import static io.appium.java_client.android.AndroidMobileCommandHelper.getDeviceDensityCommand; +import static io.appium.java_client.android.AndroidMobileCommandHelper.getSystemBarsCommand; + +public interface HasDeviceDetails extends ExecutesMethod { + /* + Retrieve the display density of the Android device. + */ + default String getDisplayDensity() { + return CommandExecutionHelper.execute(this, getDeviceDensityCommand()); + } + + /* + Retrieve visibility and bounds information of the status and navigation bars. + */ + default String getSystemBars() { + return CommandExecutionHelper.execute(this, getSystemBarsCommand()); + } +} diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 80cba36ab..2c7b7ef8f 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -55,7 +55,10 @@ public class MobileCommand { //Android protected static final String CURRENT_ACTIVITY = "currentActivity"; protected static final String END_TEST_COVERAGE = "endTestCoverage"; + protected static final String GET_DISPLAY_DENSITY = "getDisplayDensity"; protected static final String GET_NETWORK_CONNECTION = "getNetworkConnection"; + protected static final String GET_SYSTEM_BARS = "getSystemBars"; + protected static final String IS_KEYBOARD_SHOWN = "isKeyboardShown"; protected static final String IS_LOCKED = "isLocked"; protected static final String LONG_PRESS_KEY_CODE = "longPressKeyCode"; protected static final String OPEN_NOTIFICATIONS = "openNotifications"; @@ -100,7 +103,10 @@ private static Map createCommandRepository() { getC("/session/:sessionId/appium/device/current_activity")); result.put(END_TEST_COVERAGE, postC("/session/:sessionId/appium/app/end_test_coverage")); + result.put(GET_DISPLAY_DENSITY, getC("/session/:sessionId/appium/device/display_density")); result.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection")); + result.put(GET_SYSTEM_BARS, getC("/session/:sessionId/appium/device/system_bars")); + result.put(IS_KEYBOARD_SHOWN, postC("/session/:sessionId/appium/device/is_keyboard_shown")); result.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked")); result.put(LONG_PRESS_KEY_CODE, postC("/session/:sessionId/appium/device/long_press_keycode")); diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 2ccae1c34..b5a235711 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -23,6 +23,7 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.FindsByAndroidUIAutomator; +import io.appium.java_client.HasDeviceDetails; import io.appium.java_client.PressesKeyCode; import io.appium.java_client.android.internal.JsonToAndroidElementConverter; import io.appium.java_client.remote.MobilePlatform; @@ -48,7 +49,8 @@ public class AndroidDriver extends AppiumDriver implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity, - FindsByAndroidUIAutomator, LocksAndroidDevice, HasSettings { + FindsByAndroidUIAutomator, LocksAndroidDevice, HasSettings, IsKeyboardShown, + HasDeviceDetails { private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID; diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java index 450965707..07a3bbd69 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -63,6 +63,18 @@ public class AndroidMobileCommandHelper extends MobileCommand { END_TEST_COVERAGE, prepareArguments(parameters, values)); } + /** + * This method forms a {@link java.util.Map} of parameters for the + * getting of a display density value. + * + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> getDeviceDensityCommand() { + return new AbstractMap.SimpleEntry<>( + GET_DISPLAY_DENSITY, ImmutableMap.of()); + } + /** * This method forms a {@link java.util.Map} of parameters for the * getting of a network connection value. @@ -75,6 +87,30 @@ public class AndroidMobileCommandHelper extends MobileCommand { GET_NETWORK_CONNECTION, ImmutableMap.of()); } + /** + * This method forms a {@link java.util.Map} of parameters for the + * getting of a display density value. + * + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> getSystemBarsCommand() { + return new AbstractMap.SimpleEntry<>( + GET_SYSTEM_BARS, ImmutableMap.of()); + } + + /** + * This method forms a {@link java.util.Map} of parameters for the + * checking of the keyboard state (is it shown or not). + * + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> isKeyboardShownCommand() { + return new AbstractMap.SimpleEntry<>( + IS_KEYBOARD_SHOWN, ImmutableMap.of()); + } + /** * This method forms a {@link java.util.Map} of parameters for the * checking of the device state (is it locked or not). diff --git a/src/main/java/io/appium/java_client/android/IsKeyboardShown.java b/src/main/java/io/appium/java_client/android/IsKeyboardShown.java new file mode 100644 index 000000000..dfc8dcb0e --- /dev/null +++ b/src/main/java/io/appium/java_client/android/IsKeyboardShown.java @@ -0,0 +1,17 @@ +package io.appium.java_client.android; + +import static io.appium.java_client.android.AndroidMobileCommandHelper.isKeyboardShownCommand; + +import io.appium.java_client.CommandExecutionHelper; +import io.appium.java_client.ExecutesMethod; + +public interface IsKeyboardShown extends ExecutesMethod { + /** + * Check if the keyboard is displayed. + * + * @return true if keyboard is displayed. False otherwise + */ + default boolean isKeyboardShown() { + return CommandExecutionHelper.execute(this, isKeyboardShownCommand()); + } +} diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index a3ce70453..5f90f56ff 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -27,40 +27,9 @@ public class AndroidSearchingTest extends BaseAndroidTest { - @Before - public void setup() throws Exception { - driver.startActivity("io.appium.android.apis", ".ApiDemos"); - } - @Test public void findByAccessibilityIdTest() { - assertNotEquals(driver.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null); - assertEquals(driver.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1); - } - - @Test public void findByAndroidUIAutomatorTest() { - assertNotEquals(driver - .findElement(MobileBy - .AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null); - assertNotEquals(driver - .findElements(MobileBy - .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0); - assertNotEquals(driver - .findElements(MobileBy - .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1); - } - - @Test public void findByXPathTest() { - String byXPath = "//android.widget.TextView[contains(@text, 'Animat')]"; - assertNotNull(driver.findElementByXPath(byXPath).getText()); - assertEquals(driver.findElementsByXPath(byXPath).size(), 1); - } - - @Test public void findScrollable() { - driver.findElementByAccessibilityId("Views").click(); - MobileElement radioGroup = driver - .findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()" - + ".resourceId(\"android:id/list\")).scrollIntoView(" - + "new UiSelector().text(\"Radio Group\"));"); - assertNotNull(radioGroup.getLocation()); + driver.isKeyboardShown(); + System.out.println(driver.getDisplayDensity()); + System.out.println(driver.getSystemBars()); } } diff --git a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java b/src/test/java/io/appium/java_client/android/BaseAndroidTest.java index 0bfc350d6..2c87af480 100644 --- a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java +++ b/src/test/java/io/appium/java_client/android/BaseAndroidTest.java @@ -25,6 +25,7 @@ import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; +import java.net.URL; public class BaseAndroidTest { private static AppiumDriverLocalService service; @@ -34,19 +35,13 @@ public class BaseAndroidTest { * initialization. */ @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); - } - - File appDir = new File("src/test/java/io/appium/java_client"); + File appDir = new File("/Users/ssekar"); File app = new File(appDir, "ApiDemos-debug.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new AndroidDriver<>(service.getUrl(), capabilities); + driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } /** From d42df2be74637c139b5c112ab8bcc9e5409be5d9 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 20 Nov 2016 01:24:48 +0530 Subject: [PATCH 16/20] Fixed Tests --- .../android/AndroidSearchingTest.java | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index 5f90f56ff..224e00ba2 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -16,20 +16,55 @@ package io.appium.java_client.android; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.*; + public class AndroidSearchingTest extends BaseAndroidTest { + @Before + public void setup() throws Exception { + driver.startActivity("io.appium.android.apis", ".ApiDemos"); + } + @Test public void findByAccessibilityIdTest() { - driver.isKeyboardShown(); - System.out.println(driver.getDisplayDensity()); - System.out.println(driver.getSystemBars()); + assertNotEquals(driver.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null); + assertEquals(driver.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1); + } + + @Test public void findByAndroidUIAutomatorTest() { + assertNotEquals(driver + .findElement(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null); + assertNotEquals(driver + .findElements(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0); + assertNotEquals(driver + .findElements(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1); + } + + @Test public void findByXPathTest() { + String byXPath = "//android.widget.TextView[contains(@text, 'Animat')]"; + assertNotNull(driver.findElementByXPath(byXPath).getText()); + assertEquals(driver.findElementsByXPath(byXPath).size(), 1); + } + + @Test public void findScrollable() { + driver.findElementByAccessibilityId("Views").click(); + MobileElement radioGroup = driver + .findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()" + + ".resourceId(\"android:id/list\")).scrollIntoView(" + + "new UiSelector().text(\"Radio Group\"));"); + assertNotNull(radioGroup.getLocation()); + } + + @Test public void deviceDetailsAndKeyboardTest() { + assertFalse(driver.isKeyboardShown()); + assertNotNull(driver.getDisplayDensity()); + assertNotNull(driver.getSystemBars()); } } From db74f179a0da3ede4c109651b1025131c20c23c2 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Wed, 23 Nov 2016 00:03:50 +0530 Subject: [PATCH 17/20] Refractoring Refractoring --- .../appium/java_client/HasDeviceDetails.java | 13 +++++----- .../io/appium/java_client/MobileCommand.java | 2 +- .../android/AndroidMobileCommandHelper.java | 24 ------------------- .../android/AndroidSearchingTest.java | 2 +- .../java_client/android/BaseAndroidTest.java | 13 +++++++--- 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/main/java/io/appium/java_client/HasDeviceDetails.java b/src/main/java/io/appium/java_client/HasDeviceDetails.java index 7a36e9591..36157fc1e 100644 --- a/src/main/java/io/appium/java_client/HasDeviceDetails.java +++ b/src/main/java/io/appium/java_client/HasDeviceDetails.java @@ -1,21 +1,22 @@ package io.appium.java_client; +import static io.appium.java_client.MobileCommand.GET_DISPLAY_DENSITY; +import static io.appium.java_client.MobileCommand.GET_SYSTEM_BARS; -import static io.appium.java_client.android.AndroidMobileCommandHelper.getDeviceDensityCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.getSystemBarsCommand; +import java.util.Map; public interface HasDeviceDetails extends ExecutesMethod { /* Retrieve the display density of the Android device. */ - default String getDisplayDensity() { - return CommandExecutionHelper.execute(this, getDeviceDensityCommand()); + default Long getDisplayDensity() { + return CommandExecutionHelper.execute(this, GET_DISPLAY_DENSITY); } /* Retrieve visibility and bounds information of the status and navigation bars. */ - default String getSystemBars() { - return CommandExecutionHelper.execute(this, getSystemBarsCommand()); + default Map getSystemBars() { + return CommandExecutionHelper.execute(this, GET_SYSTEM_BARS); } } diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index b41f74bdc..57782caaf 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -108,7 +108,7 @@ private static Map createCommandRepository() { result.put(GET_DISPLAY_DENSITY, getC("/session/:sessionId/appium/device/display_density")); result.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection")); result.put(GET_SYSTEM_BARS, getC("/session/:sessionId/appium/device/system_bars")); - result.put(IS_KEYBOARD_SHOWN, postC("/session/:sessionId/appium/device/is_keyboard_shown")); + result.put(IS_KEYBOARD_SHOWN, getC("/session/:sessionId/appium/device/is_keyboard_shown")); result.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked")); result.put(LONG_PRESS_KEY_CODE, postC("/session/:sessionId/appium/device/long_press_keycode")); diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java index 07a3bbd69..9980ba40a 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -63,18 +63,6 @@ public class AndroidMobileCommandHelper extends MobileCommand { END_TEST_COVERAGE, prepareArguments(parameters, values)); } - /** - * This method forms a {@link java.util.Map} of parameters for the - * getting of a display density value. - * - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. - */ - public static Map.Entry> getDeviceDensityCommand() { - return new AbstractMap.SimpleEntry<>( - GET_DISPLAY_DENSITY, ImmutableMap.of()); - } - /** * This method forms a {@link java.util.Map} of parameters for the * getting of a network connection value. @@ -87,18 +75,6 @@ public class AndroidMobileCommandHelper extends MobileCommand { GET_NETWORK_CONNECTION, ImmutableMap.of()); } - /** - * This method forms a {@link java.util.Map} of parameters for the - * getting of a display density value. - * - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. - */ - public static Map.Entry> getSystemBarsCommand() { - return new AbstractMap.SimpleEntry<>( - GET_SYSTEM_BARS, ImmutableMap.of()); - } - /** * This method forms a {@link java.util.Map} of parameters for the * checking of the keyboard state (is it shown or not). diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index 224e00ba2..422aa9545 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -65,6 +65,6 @@ public void setup() throws Exception { @Test public void deviceDetailsAndKeyboardTest() { assertFalse(driver.isKeyboardShown()); assertNotNull(driver.getDisplayDensity()); - assertNotNull(driver.getSystemBars()); + assertNotEquals(0, driver.getSystemBars().size()); } } diff --git a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java b/src/test/java/io/appium/java_client/android/BaseAndroidTest.java index 2c87af480..99d379fae 100644 --- a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java +++ b/src/test/java/io/appium/java_client/android/BaseAndroidTest.java @@ -18,6 +18,7 @@ import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -25,7 +26,6 @@ import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; -import java.net.URL; public class BaseAndroidTest { private static AppiumDriverLocalService service; @@ -35,13 +35,20 @@ public class BaseAndroidTest { * initialization. */ @BeforeClass public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); - File appDir = new File("/Users/ssekar"); + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException( + "An appium server node is not started!"); + } + + 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.DEVICE_NAME, "Android Emulator"); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); + driver = new AndroidDriver<>(service.getUrl(), capabilities); } /** From a3fdeda3124791d538582b0b30d61048a1609559 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Thu, 24 Nov 2016 21:00:42 +0530 Subject: [PATCH 18/20] Fixed styling issues --- .../io/appium/java_client/android/AndroidSearchingTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index 422aa9545..138aab4e7 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -16,12 +16,16 @@ package io.appium.java_client.android; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; public class AndroidSearchingTest extends BaseAndroidTest { From 20ba01897f21ac89d3e4bbbbb66868224f22ea8d Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 26 Nov 2016 03:15:19 +0530 Subject: [PATCH 19/20] Fixed review comments --- .../appium/java_client/HasDeviceDetails.java | 22 ------------ .../java_client/android/AndroidDriver.java | 4 +-- .../android/AndroidMobileCommandHelper.java | 24 +++++++++++++ .../java_client/android/HasDeviceDetails.java | 35 +++++++++++++++++++ .../java_client/android/IsKeyboardShown.java | 17 --------- .../android/AndroidDriverTest.java | 6 ++++ .../android/AndroidSearchingTest.java | 6 ---- 7 files changed, 66 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/io/appium/java_client/HasDeviceDetails.java create mode 100644 src/main/java/io/appium/java_client/android/HasDeviceDetails.java delete mode 100644 src/main/java/io/appium/java_client/android/IsKeyboardShown.java diff --git a/src/main/java/io/appium/java_client/HasDeviceDetails.java b/src/main/java/io/appium/java_client/HasDeviceDetails.java deleted file mode 100644 index 36157fc1e..000000000 --- a/src/main/java/io/appium/java_client/HasDeviceDetails.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.appium.java_client; - -import static io.appium.java_client.MobileCommand.GET_DISPLAY_DENSITY; -import static io.appium.java_client.MobileCommand.GET_SYSTEM_BARS; - -import java.util.Map; - -public interface HasDeviceDetails extends ExecutesMethod { - /* - Retrieve the display density of the Android device. - */ - default Long getDisplayDensity() { - return CommandExecutionHelper.execute(this, GET_DISPLAY_DENSITY); - } - - /* - Retrieve visibility and bounds information of the status and navigation bars. - */ - default Map getSystemBars() { - return CommandExecutionHelper.execute(this, GET_SYSTEM_BARS); - } -} diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index b5a235711..43e1f0b2f 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -23,7 +23,6 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.FindsByAndroidUIAutomator; -import io.appium.java_client.HasDeviceDetails; import io.appium.java_client.PressesKeyCode; import io.appium.java_client.android.internal.JsonToAndroidElementConverter; import io.appium.java_client.remote.MobilePlatform; @@ -49,8 +48,7 @@ public class AndroidDriver extends AppiumDriver implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity, - FindsByAndroidUIAutomator, LocksAndroidDevice, HasSettings, IsKeyboardShown, - HasDeviceDetails { + FindsByAndroidUIAutomator, LocksAndroidDevice, HasSettings, HasDeviceDetails { private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID; diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java index 9980ba40a..e9ea6b6dd 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -63,6 +63,18 @@ public class AndroidMobileCommandHelper extends MobileCommand { END_TEST_COVERAGE, prepareArguments(parameters, values)); } + /** + * This method forms a {@link java.util.Map} of parameters to + * Retrieve the display density of the Android device. + * + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> getDisplayDensityCommand() { + return new AbstractMap.SimpleEntry<>( + GET_DISPLAY_DENSITY, ImmutableMap.of()); + } + /** * This method forms a {@link java.util.Map} of parameters for the * getting of a network connection value. @@ -75,6 +87,18 @@ public class AndroidMobileCommandHelper extends MobileCommand { GET_NETWORK_CONNECTION, ImmutableMap.of()); } + /** + * This method forms a {@link java.util.Map} of parameters to + * Retrieve visibility and bounds information of the status and navigation bars. + * + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> getSystemBarsCommand() { + return new AbstractMap.SimpleEntry<>( + GET_SYSTEM_BARS, ImmutableMap.of()); + } + /** * This method forms a {@link java.util.Map} of parameters for the * checking of the keyboard state (is it shown or not). diff --git a/src/main/java/io/appium/java_client/android/HasDeviceDetails.java b/src/main/java/io/appium/java_client/android/HasDeviceDetails.java new file mode 100644 index 000000000..30b28cefe --- /dev/null +++ b/src/main/java/io/appium/java_client/android/HasDeviceDetails.java @@ -0,0 +1,35 @@ +package io.appium.java_client.android; + +import static io.appium.java_client.android.AndroidMobileCommandHelper.getDisplayDensityCommand; +import static io.appium.java_client.android.AndroidMobileCommandHelper.getSystemBarsCommand; +import static io.appium.java_client.android.AndroidMobileCommandHelper.isKeyboardShownCommand; + +import io.appium.java_client.CommandExecutionHelper; +import io.appium.java_client.ExecutesMethod; + +import java.util.Map; + +public interface HasDeviceDetails extends ExecutesMethod { + /* + Retrieve the display density of the Android device. + */ + default Long getDisplayDensity() { + return CommandExecutionHelper.execute(this, getDisplayDensityCommand()); + } + + /* + Retrieve visibility and bounds information of the status and navigation bars. + */ + default Map getSystemBars() { + return CommandExecutionHelper.execute(this, getSystemBarsCommand()); + } + + /** + * Check if the keyboard is displayed. + * + * @return true if keyboard is displayed. False otherwise + */ + default boolean isKeyboardShown() { + return CommandExecutionHelper.execute(this, isKeyboardShownCommand()); + } +} diff --git a/src/main/java/io/appium/java_client/android/IsKeyboardShown.java b/src/main/java/io/appium/java_client/android/IsKeyboardShown.java deleted file mode 100644 index dfc8dcb0e..000000000 --- a/src/main/java/io/appium/java_client/android/IsKeyboardShown.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.appium.java_client.android; - -import static io.appium.java_client.android.AndroidMobileCommandHelper.isKeyboardShownCommand; - -import io.appium.java_client.CommandExecutionHelper; -import io.appium.java_client.ExecutesMethod; - -public interface IsKeyboardShown extends ExecutesMethod { - /** - * Check if the keyboard is displayed. - * - * @return true if keyboard is displayed. False otherwise - */ - default boolean isKeyboardShown() { - return CommandExecutionHelper.execute(this, isKeyboardShownCommand()); - } -} diff --git a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java index 19c4a778c..186bc6e47 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -134,4 +134,10 @@ public class AndroidDriverTest extends BaseAndroidTest { Map map = (Map) driver.getSessionDetail("desired"); assertNotEquals(map.size(), 0); } + + @Test public void deviceDetailsAndKeyboardTest() { + assertFalse(driver.isKeyboardShown()); + assertNotNull(driver.getDisplayDensity()); + assertNotEquals(0, driver.getSystemBars().size()); + } } diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index 138aab4e7..c17eea237 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -65,10 +65,4 @@ public void setup() throws Exception { + "new UiSelector().text(\"Radio Group\"));"); assertNotNull(radioGroup.getLocation()); } - - @Test public void deviceDetailsAndKeyboardTest() { - assertFalse(driver.isKeyboardShown()); - assertNotNull(driver.getDisplayDensity()); - assertNotEquals(0, driver.getSystemBars().size()); - } } From 358bdcebc1003c2abfeb85b9de74c960eed27218 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 26 Nov 2016 03:28:46 +0530 Subject: [PATCH 20/20] Fixed review comments --- .../java/io/appium/java_client/android/AndroidSearchingTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index c17eea237..6b3dde8e6 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -17,7 +17,6 @@ package io.appium.java_client.android; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull;