Skip to content

Commit 67bccce

Browse files
Add isKeyboardShown command for iOS (appium#887)
* Add isKeyboardShown command for iOS * Add keyboard test for iOS * Update review comments * update review comments * update review comments * make travis happy
1 parent 69054c5 commit 67bccce

File tree

7 files changed

+38
-23
lines changed

7 files changed

+38
-23
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.appium.java_client;
2+
3+
import static io.appium.java_client.MobileCommand.isKeyboardShownCommand;
4+
5+
public interface HasOnScreenKeyboard extends ExecutesMethod {
6+
7+
/**
8+
* Check if the keyboard is displayed.
9+
*
10+
* @return true if keyboard is displayed. False otherwise
11+
*/
12+
default boolean isKeyboardShown() {
13+
return CommandExecutionHelper.execute(this, isKeyboardShownCommand());
14+
}
15+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,14 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
515515
new String(img2Data, StandardCharsets.UTF_8), options.build()};
516516
return new AbstractMap.SimpleEntry<>(COMPARE_IMAGES, prepareArguments(parameters, values));
517517
}
518+
519+
/**
520+
* This method forms a {@link Map} of parameters for the checking of the keyboard state (is it shown or not).
521+
*
522+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
523+
*/
524+
public static Map.Entry<String, Map<String, ?>> isKeyboardShownCommand() {
525+
return new AbstractMap.SimpleEntry<>(
526+
IS_KEYBOARD_SHOWN, ImmutableMap.<String, Object>of());
527+
}
518528
}

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

Lines changed: 3 additions & 2 deletions
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.HasOnScreenKeyboard;
2627
import io.appium.java_client.LocksDevice;
2728
import io.appium.java_client.PressesKeyCode;
2829
import io.appium.java_client.android.connection.HasNetworkConnection;
@@ -51,8 +52,8 @@
5152
public class AndroidDriver<T extends WebElement>
5253
extends AppiumDriver<T>
5354
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
54-
FindsByAndroidUIAutomator<T>, LocksDevice, HasAndroidSettings, HasDeviceDetails,
55-
HasSupportedPerformanceDataType, AuthenticatesByFinger,
55+
FindsByAndroidUIAutomator<T>, LocksDevice, HasAndroidSettings, HasAndroidDeviceDetails,
56+
HasSupportedPerformanceDataType, AuthenticatesByFinger, HasOnScreenKeyboard,
5657
CanRecordScreen, SupportsSpecialEmulatorCommands,
5758
SupportsNetworkStateManagement, ListensToLogcatMessages, HasAndroidClipboard {
5859

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,6 @@ public class AndroidMobileCommandHelper extends MobileCommand {
152152
GET_SYSTEM_BARS, ImmutableMap.<String, Object>of());
153153
}
154154

155-
/**
156-
* This method forms a {@link Map} of parameters for the checking of the keyboard state (is it shown or not).
157-
*
158-
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
159-
*/
160-
public static Map.Entry<String, Map<String, ?>> isKeyboardShownCommand() {
161-
return new AbstractMap.SimpleEntry<>(
162-
IS_KEYBOARD_SHOWN, ImmutableMap.<String, Object>of());
163-
}
164-
165155
/**
166156
* This method forms a {@link java.util.Map} of parameters for the
167157
* finger print authentication invocation.

src/main/java/io/appium/java_client/android/HasDeviceDetails.java renamed to src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import static io.appium.java_client.android.AndroidMobileCommandHelper.getDisplayDensityCommand;
44
import static io.appium.java_client.android.AndroidMobileCommandHelper.getSystemBarsCommand;
5-
import static io.appium.java_client.android.AndroidMobileCommandHelper.isKeyboardShownCommand;
65

76
import io.appium.java_client.CommandExecutionHelper;
87
import io.appium.java_client.ExecutesMethod;
98

109
import java.util.Map;
1110

12-
public interface HasDeviceDetails extends ExecutesMethod {
11+
public interface HasAndroidDeviceDetails extends ExecutesMethod {
12+
1313
/*
1414
Retrieve the display density of the Android device.
1515
*/
@@ -24,12 +24,4 @@ default Map<String, String> getSystemBars() {
2424
return CommandExecutionHelper.execute(this, getSystemBarsCommand());
2525
}
2626

27-
/**
28-
* Check if the keyboard is displayed.
29-
*
30-
* @return true if keyboard is displayed. False otherwise
31-
*/
32-
default boolean isKeyboardShown() {
33-
return CommandExecutionHelper.execute(this, isKeyboardShownCommand());
34-
}
3527
}

src/main/java/io/appium/java_client/ios/IOSDriver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.appium.java_client.FindsByIosClassChain;
2424
import io.appium.java_client.FindsByIosNSPredicate;
2525
import io.appium.java_client.FindsByIosUIAutomation;
26+
import io.appium.java_client.HasOnScreenKeyboard;
2627
import io.appium.java_client.HidesKeyboardWithKeyName;
2728
import io.appium.java_client.LocksDevice;
2829
import io.appium.java_client.remote.MobilePlatform;
@@ -54,7 +55,7 @@
5455
*/
5556
public class IOSDriver<T extends WebElement>
5657
extends AppiumDriver<T>
57-
implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings,
58+
implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings, HasOnScreenKeyboard,
5859
FindsByIosUIAutomation<T>, LocksDevice, PerformsTouchID, FindsByIosNSPredicate<T>,
5960
FindsByIosClassChain<T>, PushesFiles, CanRecordScreen, HasIOSClipboard, ListensToSyslogMessages {
6061

src/test/java/io/appium/java_client/ios/IOSDriverTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ public void getDeviceTimeTest() {
7373
byte[] data = driver.pullFile("Library/AddressBook/AddressBook.sqlitedb");
7474
assert (data.length > 0);
7575
}
76+
77+
@Test public void keyboardTest() {
78+
MobileElement element = driver.findElementById("IntegerA");
79+
element.click();
80+
assertTrue(driver.isKeyboardShown());
81+
}
7682
}

0 commit comments

Comments
 (0)