diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 7923ca347..57782caaf 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -56,7 +56,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"; @@ -102,7 +105,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, 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/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 2ccae1c34..43e1f0b2f 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -48,7 +48,7 @@ public class AndroidDriver extends AppiumDriver implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity, - FindsByAndroidUIAutomator, LocksAndroidDevice, HasSettings { + 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 450965707..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,30 @@ 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). + * + * @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/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/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 a3ce70453..6b3dde8e6 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -25,6 +25,7 @@ import org.junit.Before; import org.junit.Test; + public class AndroidSearchingTest extends BaseAndroidTest { @Before 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..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; @@ -38,7 +39,8 @@ public class BaseAndroidTest { 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");