Skip to content

Commit 9ae8606

Browse files
Added isKeyboardShown,getDisplayDensity and getSystemBars Commands
1 parent 5b9a7c0 commit 9ae8606

File tree

7 files changed

+89
-43
lines changed

7 files changed

+89
-43
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.appium.java_client;
2+
3+
4+
import static io.appium.java_client.android.AndroidMobileCommandHelper.getDeviceDensityCommand;
5+
import static io.appium.java_client.android.AndroidMobileCommandHelper.getSystemBarsCommand;
6+
7+
public interface HasDeviceDetails extends ExecutesMethod {
8+
/*
9+
Retrieve the display density of the Android device.
10+
*/
11+
default String getDisplayDensity() {
12+
return CommandExecutionHelper.execute(this, getDeviceDensityCommand());
13+
}
14+
15+
/*
16+
Retrieve visibility and bounds information of the status and navigation bars.
17+
*/
18+
default String getSystemBars() {
19+
return CommandExecutionHelper.execute(this, getSystemBarsCommand());
20+
}
21+
}

src/main/java/io/appium/java_client/MobileCommand.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public class MobileCommand {
5555
//Android
5656
protected static final String CURRENT_ACTIVITY = "currentActivity";
5757
protected static final String END_TEST_COVERAGE = "endTestCoverage";
58+
protected static final String GET_DISPLAY_DENSITY = "getDisplayDensity";
5859
protected static final String GET_NETWORK_CONNECTION = "getNetworkConnection";
60+
protected static final String GET_SYSTEM_BARS = "getSystemBars";
61+
protected static final String IS_KEYBOARD_SHOWN = "isKeyboardShown";
5962
protected static final String IS_LOCKED = "isLocked";
6063
protected static final String LONG_PRESS_KEY_CODE = "longPressKeyCode";
6164
protected static final String OPEN_NOTIFICATIONS = "openNotifications";
@@ -100,7 +103,10 @@ private static Map<String, CommandInfo> createCommandRepository() {
100103
getC("/session/:sessionId/appium/device/current_activity"));
101104
result.put(END_TEST_COVERAGE,
102105
postC("/session/:sessionId/appium/app/end_test_coverage"));
106+
result.put(GET_DISPLAY_DENSITY, getC("/session/:sessionId/appium/device/display_density"));
103107
result.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection"));
108+
result.put(GET_SYSTEM_BARS, getC("/session/:sessionId/appium/device/system_bars"));
109+
result.put(IS_KEYBOARD_SHOWN, postC("/session/:sessionId/appium/device/is_keyboard_shown"));
104110
result.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked"));
105111
result.put(LONG_PRESS_KEY_CODE,
106112
postC("/session/:sessionId/appium/device/long_press_keycode"));

src/main/java/io/appium/java_client/android/AndroidDriver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.appium.java_client.AppiumDriver;
2424
import io.appium.java_client.CommandExecutionHelper;
2525
import io.appium.java_client.FindsByAndroidUIAutomator;
26+
import io.appium.java_client.HasDeviceDetails;
2627
import io.appium.java_client.PressesKeyCode;
2728
import io.appium.java_client.android.internal.JsonToAndroidElementConverter;
2829
import io.appium.java_client.remote.MobilePlatform;
@@ -48,7 +49,8 @@
4849
public class AndroidDriver<T extends WebElement>
4950
extends AppiumDriver<T>
5051
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
51-
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasSettings {
52+
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasSettings, IsKeyboardShown,
53+
HasDeviceDetails {
5254

5355
private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;
5456

src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public class AndroidMobileCommandHelper extends MobileCommand {
6363
END_TEST_COVERAGE, prepareArguments(parameters, values));
6464
}
6565

66+
/**
67+
* This method forms a {@link java.util.Map} of parameters for the
68+
* getting of a display density value.
69+
*
70+
* @return a key-value pair. The key is the command name. The value is a
71+
* {@link java.util.Map} command arguments.
72+
*/
73+
public static Map.Entry<String, Map<String, ?>> getDeviceDensityCommand() {
74+
return new AbstractMap.SimpleEntry<>(
75+
GET_DISPLAY_DENSITY, ImmutableMap.<String, Object>of());
76+
}
77+
6678
/**
6779
* This method forms a {@link java.util.Map} of parameters for the
6880
* getting of a network connection value.
@@ -75,6 +87,30 @@ public class AndroidMobileCommandHelper extends MobileCommand {
7587
GET_NETWORK_CONNECTION, ImmutableMap.<String, Object>of());
7688
}
7789

90+
/**
91+
* This method forms a {@link java.util.Map} of parameters for the
92+
* getting of a display density value.
93+
*
94+
* @return a key-value pair. The key is the command name. The value is a
95+
* {@link java.util.Map} command arguments.
96+
*/
97+
public static Map.Entry<String, Map<String, ?>> getSystemBarsCommand() {
98+
return new AbstractMap.SimpleEntry<>(
99+
GET_SYSTEM_BARS, ImmutableMap.<String, Object>of());
100+
}
101+
102+
/**
103+
* This method forms a {@link java.util.Map} of parameters for the
104+
* checking of the keyboard state (is it shown or not).
105+
*
106+
* @return a key-value pair. The key is the command name. The value is a
107+
* {@link java.util.Map} command arguments.
108+
*/
109+
public static Map.Entry<String, Map<String, ?>> isKeyboardShownCommand() {
110+
return new AbstractMap.SimpleEntry<>(
111+
IS_KEYBOARD_SHOWN, ImmutableMap.<String, Object>of());
112+
}
113+
78114
/**
79115
* This method forms a {@link java.util.Map} of parameters for the
80116
* checking of the device state (is it locked or not).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.appium.java_client.android;
2+
3+
import static io.appium.java_client.android.AndroidMobileCommandHelper.isKeyboardShownCommand;
4+
5+
import io.appium.java_client.CommandExecutionHelper;
6+
import io.appium.java_client.ExecutesMethod;
7+
8+
public interface IsKeyboardShown extends ExecutesMethod {
9+
/**
10+
* Check if the keyboard is displayed.
11+
*
12+
* @return true if keyboard is displayed. False otherwise
13+
*/
14+
default boolean isKeyboardShown() {
15+
return CommandExecutionHelper.execute(this, isKeyboardShownCommand());
16+
}
17+
}

src/test/java/io/appium/java_client/android/AndroidSearchingTest.java

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,9 @@
2727

2828
public class AndroidSearchingTest extends BaseAndroidTest {
2929

30-
@Before
31-
public void setup() throws Exception {
32-
driver.startActivity("io.appium.android.apis", ".ApiDemos");
33-
}
34-
3530
@Test public void findByAccessibilityIdTest() {
36-
assertNotEquals(driver.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null);
37-
assertEquals(driver.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1);
38-
}
39-
40-
@Test public void findByAndroidUIAutomatorTest() {
41-
assertNotEquals(driver
42-
.findElement(MobileBy
43-
.AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
44-
assertNotEquals(driver
45-
.findElements(MobileBy
46-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
47-
assertNotEquals(driver
48-
.findElements(MobileBy
49-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
50-
}
51-
52-
@Test public void findByXPathTest() {
53-
String byXPath = "//android.widget.TextView[contains(@text, 'Animat')]";
54-
assertNotNull(driver.findElementByXPath(byXPath).getText());
55-
assertEquals(driver.findElementsByXPath(byXPath).size(), 1);
56-
}
57-
58-
@Test public void findScrollable() {
59-
driver.findElementByAccessibilityId("Views").click();
60-
MobileElement radioGroup = driver
61-
.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"
62-
+ ".resourceId(\"android:id/list\")).scrollIntoView("
63-
+ "new UiSelector().text(\"Radio Group\"));");
64-
assertNotNull(radioGroup.getLocation());
31+
driver.isKeyboardShown();
32+
System.out.println(driver.getDisplayDensity());
33+
System.out.println(driver.getSystemBars());
6534
}
6635
}

src/test/java/io/appium/java_client/android/BaseAndroidTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.openqa.selenium.remote.DesiredCapabilities;
2626

2727
import java.io.File;
28+
import java.net.URL;
2829

2930
public class BaseAndroidTest {
3031
private static AppiumDriverLocalService service;
@@ -34,19 +35,13 @@ public class BaseAndroidTest {
3435
* initialization.
3536
*/
3637
@BeforeClass public static void beforeClass() throws Exception {
37-
service = AppiumDriverLocalService.buildDefaultService();
38-
service.start();
3938

40-
if (service == null || !service.isRunning()) {
41-
throw new RuntimeException("An appium server node is not started!");
42-
}
43-
44-
File appDir = new File("src/test/java/io/appium/java_client");
39+
File appDir = new File("/Users/ssekar");
4540
File app = new File(appDir, "ApiDemos-debug.apk");
4641
DesiredCapabilities capabilities = new DesiredCapabilities();
4742
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
4843
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
49-
driver = new AndroidDriver<>(service.getUrl(), capabilities);
44+
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
5045
}
5146

5247
/**

0 commit comments

Comments
 (0)