Skip to content

Add isKeyboardShown command for iOS #887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*/
@SuppressWarnings("unchecked")
public class AppiumDriver<T extends WebElement>
extends DefaultGenericMobileDriver<T> implements ComparesImages {
extends DefaultGenericMobileDriver<T> implements ComparesImages, HasDeviceDetails {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather add it to only ios and Android drivers, but not to the generic one.


private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);
// frequently used command parameters
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/appium/java_client/HasDeviceDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.appium.java_client;

import static io.appium.java_client.MobileCommand.isKeyboardShownCommand;

public interface HasDeviceDetails extends ExecutesMethod {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather rename the interface to HasOnScreenKeyboard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm makes sense


/**
* Check if the keyboard is displayed.
*
* @return true if keyboard is displayed. False otherwise
*/
default boolean isKeyboardShown() {
return CommandExecutionHelper.execute(this, isKeyboardShownCommand());
}
}
10 changes: 10 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,14 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
new String(img2Data, StandardCharsets.UTF_8), options.build()};
return new AbstractMap.SimpleEntry<>(COMPARE_IMAGES, prepareArguments(parameters, values));
}

/**
* This method forms a {@link 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 Map} command arguments.
*/
public static Map.Entry<String, Map<String, ?>> isKeyboardShownCommand() {
return new AbstractMap.SimpleEntry<>(
IS_KEYBOARD_SHOWN, ImmutableMap.<String, Object>of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
public class AndroidDriver<T extends WebElement>
extends AppiumDriver<T>
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
FindsByAndroidUIAutomator<T>, LocksDevice, HasAndroidSettings, HasDeviceDetails,
FindsByAndroidUIAutomator<T>, LocksDevice, HasAndroidSettings, HasAndroidDeviceDetails,
HasSupportedPerformanceDataType, AuthenticatesByFinger,
CanRecordScreen, SupportsSpecialEmulatorCommands,
SupportsNetworkStateManagement, ListensToLogcatMessages, HasAndroidClipboard {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface should be added to AndroidDriver as well

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,6 @@ public class AndroidMobileCommandHelper extends MobileCommand {
GET_SYSTEM_BARS, ImmutableMap.<String, Object>of());
}

/**
* This method forms a {@link 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 Map} command arguments.
*/
public static Map.Entry<String, Map<String, ?>> isKeyboardShownCommand() {
return new AbstractMap.SimpleEntry<>(
IS_KEYBOARD_SHOWN, ImmutableMap.<String, Object>of());
}

/**
* This method forms a {@link java.util.Map} of parameters for the
* finger print authentication invocation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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 io.appium.java_client.HasDeviceDetails;

import java.util.Map;

public interface HasDeviceDetails extends ExecutesMethod {
import static io.appium.java_client.android.AndroidMobileCommandHelper.getDisplayDensityCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.getSystemBarsCommand;

public interface HasAndroidDeviceDetails extends HasDeviceDetails {

/*
Retrieve the display density of the Android device.
*/
Expand All @@ -24,12 +24,4 @@ default Map<String, String> 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());
}
}
6 changes: 6 additions & 0 deletions src/test/java/io/appium/java_client/ios/IOSDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@ public void getDeviceTimeTest() {
byte[] data = driver.pullFile("Library/AddressBook/AddressBook.sqlitedb");
assert (data.length > 0);
}

@Test public void keyboardTest() {
MobileElement element = driver.findElementById("IntegerA");
element.click();
assertTrue(driver.isKeyboardShown());
}
}