From b9a0005407864c410c58ee8da022ea00b8402a25 Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Thu, 11 Feb 2016 13:26:42 +0300 Subject: [PATCH] #315 fix Change list: - The _AppiumDriver.lockScreen(int seconds)_ is deprecated now. - AndroidDriver: _lockDevice()_ and _unlockDevice()_ were added - IOSDriver: _lockDevice(int seconds)_ was added --- README.md | 6 ++++- .../io/appium/java_client/AppiumDriver.java | 12 +++++---- .../io/appium/java_client/MobileCommand.java | 4 ++- .../java_client/android/AndroidDriver.java | 25 +++++++++++-------- .../io/appium/java_client/ios/IOSDriver.java | 11 ++++++++ .../android/AndroidDriverTest.java | 10 +++----- .../appium/java_client/ios/IOSDriverTest.java | 2 +- 7 files changed, 45 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 4d7f9a755..c7c873c2b 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,6 @@ More can be found in the docs, but here's a quick list of features which this pr - launchApp() - closeApp() - endTestCoverage() -- lockScreen() - isLocked() - shake() - scrollTo() @@ -95,6 +94,8 @@ More can be found in the docs, but here's a quick list of features which this pr - getNetworkConnection(), setNetworkConnection() - ignoreUnimportantViews(), getSettings() - toggleLocationServices() +- lockDevice() +- unlockDevice() Locators: - findElementByAccessibilityId() @@ -121,6 +122,9 @@ instead of a string. Thanks to [@rgonalo](https://github.com/rgonalo) for the co - FIXED `longPressKeyCode()` methods. Now they use the convenient JSONWP command.Thanks to [@kirillbilchenko](https://github.com/kirillbilchenko) for the proposed fix. - FIXED javadoc. - Page object tools were updated. Details read here: [#311](https://github.com/appium/java-client/issues/311), [#313](https://github.com/appium/java-client/pull/313), [#317](https://github.com/appium/java-client/pull/317). By.name locator strategy is deprecated for Android and iOS. It is still valid for the Selendroid mode. Thanks to [@SrinivasanTarget](https://github.com/SrinivasanTarget) for the helping. +- The method `lockScreen(seconds)` is deprecated and it is going to be removed in the next release. Since Appium node server v1.5.x it is recommended to use +`AndroidDriver.lockDevice()...AndroidDriver.unlockDevice()` or `IOSDriver.lockDevice(int seconds)` instead. Thanks to [@namannigam](https://github.com/namannigam) for +the catching. Read [#315](https://github.com/appium/java-client/issues/315) *3.3.0* - updated the dependency on Selenium to version 2.48.2 diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 83e3dd4f3..88b8ff6ab 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -536,18 +536,20 @@ protected void setSetting(AppiumSetting setting, Object value) { setSettings(getCommandImmutableMap(setting.toString(), value)); } + + @Deprecated /** - * Lock the device (bring it to the lock screen) for a given number of - * seconds + * This method works incorrectly. It is deprecated and it is going to be removed further. + * Be careful. * - * @param seconds - * number of seconds to lock the screen for + * Since Appium node 1.5.x you are free to use + * IOSDriver.lockDevice(int seconds) or AndroidDriver.lockDevice()...AndroidDriver.unlockDevice() instead */ public void lockScreen(int seconds) { execute(LOCK, ImmutableMap.of("seconds", seconds)); } - @Override + @Override public WebDriver context(String name) { if (!_isNotNullOrEmpty(name)) { throw new IllegalArgumentException("Must supply a context name"); diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 825335e0f..66584429d 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -61,6 +61,7 @@ public class MobileCommand { public final static String START_ACTIVITY = "startActivity"; public final static String TOGGLE_LOCATION_SERVICES = "toggleLocationServices"; public final static String GET_DEVICE_TIME = "getDeviceTime"; + public final static String UNLOCK = "unlock"; static CommandInfo getC(String url) { return new CommandInfo(url, HttpMethod.GET); @@ -133,7 +134,8 @@ private static Map getMobileCommands(){ .put(START_ACTIVITY, postC("/session/:sessionId/appium/device/start_activity")) .put(TOGGLE_LOCATION_SERVICES, postC("/session/:sessionId/appium/device/toggle_location_services")) - .put(GET_DEVICE_TIME,getC("/session/:sessionId/appium/device/system_time")); + .put(GET_DEVICE_TIME,getC("/session/:sessionId/appium/device/system_time")) + .put(UNLOCK, postC("/session/:sessionId/appium/device/unlock")); return builder.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 558624bd8..b201e6827 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -35,17 +35,7 @@ import java.util.List; import static com.google.common.base.Preconditions.checkArgument; -import static io.appium.java_client.MobileCommand.CURRENT_ACTIVITY; -import static io.appium.java_client.MobileCommand.END_TEST_COVERAGE; -import static io.appium.java_client.MobileCommand.GET_NETWORK_CONNECTION; -import static io.appium.java_client.MobileCommand.IS_LOCKED; -import static io.appium.java_client.MobileCommand.OPEN_NOTIFICATIONS; -import static io.appium.java_client.MobileCommand.PRESS_KEY_CODE; -import static io.appium.java_client.MobileCommand.LONG_PRESS_KEY_CODE; -import static io.appium.java_client.MobileCommand.PUSH_FILE; -import static io.appium.java_client.MobileCommand.SET_NETWORK_CONNECTION; -import static io.appium.java_client.MobileCommand.START_ACTIVITY; -import static io.appium.java_client.MobileCommand.TOGGLE_LOCATION_SERVICES; +import static io.appium.java_client.MobileCommand.*; import static io.appium.java_client.remote.MobileCapabilityType.APP_ACTIVITY; import static io.appium.java_client.remote.MobileCapabilityType.APP_PACKAGE; import static io.appium.java_client.remote.MobileCapabilityType.APP_WAIT_ACTIVITY; @@ -388,4 +378,17 @@ public List findElementsByAndroidUIAutomator(String using) return (List) findElements("-android uiautomator", using); } + /** + * This method locks a device. + */ + public void lockDevice() { + execute(LOCK, ImmutableMap.of("seconds", 0)); + } + + /** + * This method unlocks a device. + */ + public void unlockDevice() { + execute(UNLOCK); + } } 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 5f0a48dd5..d396b806e 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -180,4 +180,15 @@ public RequiredElementType findElementByIosUIAutomation(String using) throws Web public List findElementsByIosUIAutomation(String using) throws WebDriverException { return (List) findElements("-ios uiautomation", using); } + + /** + * Lock the device (bring it to the lock screen) for a given number of + * seconds + * + * @param seconds + * number of seconds to lock the screen for + */ + public void lockDevice(int seconds) { + execute(LOCK, ImmutableMap.of("seconds", seconds)); + } } 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 225e67a1c..d2616afca 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -167,11 +167,6 @@ public void networkConnectionTest() { } - @Test - public void isLockedTest() { - assertEquals(false, driver.isLocked()); - } - @Test public void ignoreUnimportantViews() { driver.ignoreUnimportantViews(true); @@ -248,7 +243,10 @@ public void orientationTest() { @Test public void lockTest() { - driver.lockScreen(20); + driver.lockDevice(); + assertEquals(true, driver.isLocked()); + driver.unlockDevice(); + assertEquals(false, driver.isLocked()); } @Test diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 7491720e9..e6b6311da 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -158,7 +158,7 @@ public void orientationTest() { @Test public void lockTest() { - driver.lockScreen(20); + driver.lockDevice(20); } @Test