From d0147d1bf6fb0b18d9ee149378e8a39bad7f3554 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 28 Apr 2023 19:58:45 +0200 Subject: [PATCH 1/2] feat: Switch more helpers to use extensions --- .../io/appium/java_client/MobileCommand.java | 18 ++-- .../java_client/android/AndroidDriver.java | 2 + .../android/AndroidMobileCommandHelper.java | 24 +++++ .../android/AuthenticatesByFinger.java | 11 +- .../android/CanReplaceElementValue.java | 26 +++-- .../android/HasAndroidDeviceDetails.java | 15 ++- .../java_client/android/StartsActivity.java | 28 ++++- .../SupportsSpecialEmulatorCommands.java | 102 +++++++++++++++--- .../android/AndroidDriverTest.java | 5 - 9 files changed, 190 insertions(+), 41 deletions(-) diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 5b2a6587d..721c854a7 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -112,7 +112,7 @@ public class MobileCommand { protected static final String TOUCH_ID_ENROLLMENT; //Android @Deprecated - protected static final String CURRENT_ACTIVITY; + public static final String CURRENT_ACTIVITY; @Deprecated protected static final String END_TEST_COVERAGE; @Deprecated @@ -149,21 +149,21 @@ public class MobileCommand { @Deprecated protected static final String SET_SETTINGS; @Deprecated - protected static final String GET_CURRENT_PACKAGE; + public static final String GET_CURRENT_PACKAGE; @Deprecated - protected static final String SEND_SMS; + public static final String SEND_SMS; @Deprecated - protected static final String GSM_CALL; + public static final String GSM_CALL; @Deprecated - protected static final String GSM_SIGNAL; + public static final String GSM_SIGNAL; @Deprecated - protected static final String GSM_VOICE; + public static final String GSM_VOICE; @Deprecated - protected static final String NETWORK_SPEED; + public static final String NETWORK_SPEED; @Deprecated - protected static final String POWER_CAPACITY; + public static final String POWER_CAPACITY; @Deprecated - protected static final String POWER_AC_STATE; + public static final String POWER_AC_STATE; @Deprecated protected static final String TOGGLE_WIFI; @Deprecated 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 c7290882b..9606be761 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -255,7 +255,9 @@ public AndroidDriver(URL remoteSessionAddress, String automationName) { * * @param intent intent to broadcast. * @param path path to .ec file. + * @deprecated This API will be removed */ + @Deprecated public void endTestCoverage(String intent, String path) { CommandExecutionHelper.execute(this, endTestCoverageCommand(intent, path)); } 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 6b46ce945..1bed116d7 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -37,6 +37,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> currentActivityCommand() { return new AbstractMap.SimpleEntry<>(CURRENT_ACTIVITY, ImmutableMap.of()); } @@ -46,6 +47,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> currentPackageCommand() { return new AbstractMap.SimpleEntry<>(GET_CURRENT_PACKAGE, ImmutableMap.of()); } @@ -57,6 +59,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * @param path path to .ec file. * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> endTestCoverageCommand(String intent, String path) { String[] parameters = new String[] {"intent", "path"}; @@ -117,6 +120,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> getDisplayDensityCommand() { return new AbstractMap.SimpleEntry<>(GET_DISPLAY_DENSITY, ImmutableMap.of()); } @@ -126,6 +130,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> getNetworkConnectionCommand() { return new AbstractMap.SimpleEntry<>(GET_NETWORK_CONNECTION, ImmutableMap.of()); } @@ -136,6 +141,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> getSystemBarsCommand() { return new AbstractMap.SimpleEntry<>(GET_SYSTEM_BARS, ImmutableMap.of()); } @@ -145,6 +151,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> isLockedCommand() { return new AbstractMap.SimpleEntry<>(IS_LOCKED, ImmutableMap.of()); } @@ -155,6 +162,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * @param fingerPrintId finger prints stored in Android Keystore system (from 1 to 10) * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> fingerPrintCommand(int fingerPrintId) { return new AbstractMap.SimpleEntry<>(FINGER_PRINT, prepareArguments("fingerprintId", fingerPrintId)); @@ -165,6 +173,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> openNotificationsCommand() { return new AbstractMap.SimpleEntry<>(OPEN_NOTIFICATIONS, ImmutableMap.of()); } @@ -175,6 +184,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * @param bitMask The bitmask of the desired connection * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> setConnectionCommand(long bitMask) { String[] parameters = new String[] {"name", "parameters"}; Object[] values = new Object[] {"network_connection", ImmutableMap.of("type", bitMask)}; @@ -198,6 +208,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. * @throws IllegalArgumentException when any required argument is empty */ + @Deprecated public static Map.Entry> startActivityCommand(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity, String intentAction, String intentCategory, String intentFlags, @@ -234,6 +245,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> toggleLocationServicesCommand() { return new AbstractMap.SimpleEntry<>(TOGGLE_LOCATION_SERVICES, ImmutableMap.of()); } @@ -243,6 +255,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> unlockCommand() { return new AbstractMap.SimpleEntry<>(UNLOCK, ImmutableMap.of()); } @@ -256,6 +269,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * @param value a new value * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> replaceElementValueCommand( RemoteWebElement remoteWebElement, String value) { String[] parameters = new String[] {"id", "value"}; @@ -275,6 +289,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> sendSMSCommand( String phoneNumber, String message) { ImmutableMap parameters = ImmutableMap @@ -294,6 +309,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> gsmCallCommand( String phoneNumber, GsmCallActions gsmCallActions) { String[] parameters = new String[] {"phoneNumber", "action"}; @@ -309,6 +325,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> gsmSignalStrengthCommand( GsmSignalStrength gsmSignalStrength) { return new AbstractMap.SimpleEntry<>(GSM_SIGNAL, @@ -327,6 +344,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> gsmVoiceCommand( GsmVoiceState gsmVoiceState) { return new AbstractMap.SimpleEntry<>(GSM_VOICE, @@ -341,6 +359,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> networkSpeedCommand( NetworkSpeed networkSpeed) { return new AbstractMap.SimpleEntry<>(NETWORK_SPEED, @@ -355,6 +374,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> powerCapacityCommand( int percent) { return new AbstractMap.SimpleEntry<>(POWER_CAPACITY, @@ -369,6 +389,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> powerACCommand( PowerACState powerACState) { return new AbstractMap.SimpleEntry<>(POWER_AC_STATE, @@ -380,6 +401,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> toggleWifiCommand() { return new AbstractMap.SimpleEntry<>(TOGGLE_WIFI, ImmutableMap.of()); } @@ -389,6 +411,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> toggleAirplaneCommand() { return new AbstractMap.SimpleEntry<>(TOGGLE_AIRPLANE_MODE, ImmutableMap.of()); } @@ -398,6 +421,7 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ + @Deprecated public static Map.Entry> toggleDataCommand() { return new AbstractMap.SimpleEntry<>(TOGGLE_DATA, ImmutableMap.of()); } diff --git a/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java b/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java index 15503e239..0d9abe90b 100644 --- a/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java +++ b/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java @@ -1,7 +1,9 @@ package io.appium.java_client.android; +import com.google.common.collect.ImmutableMap; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; +import org.openqa.selenium.UnsupportedCommandException; import static io.appium.java_client.android.AndroidMobileCommandHelper.fingerPrintCommand; @@ -13,6 +15,13 @@ public interface AuthenticatesByFinger extends ExecutesMethod { * @param fingerPrintId finger prints stored in Android Keystore system (from 1 to 10) */ default void fingerPrint(int fingerPrintId) { - CommandExecutionHelper.execute(this, fingerPrintCommand(fingerPrintId)); + try { + CommandExecutionHelper.executeScript(this, "mobile: fingerprint", ImmutableMap.of( + "fingerprintId", fingerPrintId + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + CommandExecutionHelper.execute(this, fingerPrintCommand(fingerPrintId)); + } } } diff --git a/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java b/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java index 72a170f32..949e7964c 100644 --- a/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java +++ b/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java @@ -1,21 +1,35 @@ package io.appium.java_client.android; import com.google.common.collect.ImmutableMap; +import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; import io.appium.java_client.MobileCommand; +import org.openqa.selenium.UnsupportedCommandException; import org.openqa.selenium.remote.RemoteWebElement; public interface CanReplaceElementValue extends ExecutesMethod { /** - * Replaces element value with the given one. + * Sends a text to the given element by replacing its previous content. * * @param element The destination element. - * @param value The value to set. + * @param value The text to enter. It could also contain Unicode characters. + * If the text ends with `\\n` (the backslash must be escaped, so the + * char is NOT translated into `0x0A`) then the Enter key press is going to + * be emulated after it is entered (the `\\n` substring itself will be cut + * off from the typed text). */ default void replaceElementValue(RemoteWebElement element, String value) { - this.execute(MobileCommand.REPLACE_VALUE, ImmutableMap.of( - "id", element.getId(), - "value", value - )); + try { + CommandExecutionHelper.executeScript(this, "mobile: replaceValue", ImmutableMap.of( + "elementId", element.getId(), + "text", value + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(MobileCommand.REPLACE_VALUE, ImmutableMap.of( + "id", element.getId(), + "value", value + )); + } } } diff --git a/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java b/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java index 66c084480..bcdcf1fd4 100644 --- a/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java +++ b/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java @@ -2,6 +2,7 @@ import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; +import org.openqa.selenium.UnsupportedCommandException; import java.util.Map; @@ -16,7 +17,12 @@ public interface HasAndroidDeviceDetails extends ExecutesMethod { @return The density value in dpi */ default Long getDisplayDensity() { - return CommandExecutionHelper.execute(this, getDisplayDensityCommand()); + try { + return CommandExecutionHelper.executeScript(this, "mobile: getDisplayDensity"); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + return CommandExecutionHelper.execute(this, getDisplayDensityCommand()); + } } /** @@ -25,7 +31,12 @@ default Long getDisplayDensity() { @return The map where keys are bar types and values are mappings of bar properties. */ default Map> getSystemBars() { - return CommandExecutionHelper.execute(this, getSystemBarsCommand()); + try { + return CommandExecutionHelper.executeScript(this, "mobile: getSystemBars"); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + return CommandExecutionHelper.execute(this, getSystemBarsCommand()); + } } } diff --git a/src/main/java/io/appium/java_client/android/StartsActivity.java b/src/main/java/io/appium/java_client/android/StartsActivity.java index f01d50998..8881ff629 100644 --- a/src/main/java/io/appium/java_client/android/StartsActivity.java +++ b/src/main/java/io/appium/java_client/android/StartsActivity.java @@ -16,9 +16,17 @@ package io.appium.java_client.android; +import com.google.common.collect.ImmutableMap; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; +import org.openqa.selenium.UnsupportedCommandException; +import javax.annotation.Nullable; + +import java.util.AbstractMap; + +import static io.appium.java_client.MobileCommand.CURRENT_ACTIVITY; +import static io.appium.java_client.MobileCommand.GET_CURRENT_PACKAGE; import static io.appium.java_client.android.AndroidMobileCommandHelper.currentActivityCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.currentPackageCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.startActivityCommand; @@ -57,8 +65,16 @@ default void startActivity(Activity activity) { * * @return a current activity being run on the mobile device. */ + @Nullable default String currentActivity() { - return CommandExecutionHelper.execute(this, currentActivityCommand()); + try { + return CommandExecutionHelper.executeScript(this, "mobile: getCurrentActivity"); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + return CommandExecutionHelper.execute( + this, new AbstractMap.SimpleEntry<>(CURRENT_ACTIVITY, ImmutableMap.of()) + ); + } } /** @@ -66,7 +82,15 @@ default String currentActivity() { * * @return a current package being run on the mobile device. */ + @Nullable default String getCurrentPackage() { - return CommandExecutionHelper.execute(this, currentPackageCommand()); + try { + return CommandExecutionHelper.executeScript(this, "mobile: getCurrentPackage"); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + return CommandExecutionHelper.execute( + this, new AbstractMap.SimpleEntry<>(GET_CURRENT_PACKAGE, ImmutableMap.of()) + ); + } } } diff --git a/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java index 6baeef8a0..83f0c48b7 100644 --- a/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java +++ b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java @@ -1,15 +1,17 @@ package io.appium.java_client.android; +import com.google.common.collect.ImmutableMap; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; +import org.openqa.selenium.UnsupportedCommandException; -import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmCallCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmSignalStrengthCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmVoiceCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.networkSpeedCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.powerACCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.powerCapacityCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.sendSMSCommand; +import static io.appium.java_client.MobileCommand.GSM_CALL; +import static io.appium.java_client.MobileCommand.GSM_SIGNAL; +import static io.appium.java_client.MobileCommand.GSM_VOICE; +import static io.appium.java_client.MobileCommand.NETWORK_SPEED; +import static io.appium.java_client.MobileCommand.POWER_AC_STATE; +import static io.appium.java_client.MobileCommand.POWER_CAPACITY; +import static io.appium.java_client.MobileCommand.SEND_SMS; public interface SupportsSpecialEmulatorCommands extends ExecutesMethod { @@ -20,17 +22,39 @@ public interface SupportsSpecialEmulatorCommands extends ExecutesMethod { * @param message The message content. */ default void sendSMS(String phoneNumber, String message) { - CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message)); + try { + CommandExecutionHelper.executeScript(this, "mobile: sendSms", ImmutableMap.of( + "phoneNumber", phoneNumber, + "message", message + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(SEND_SMS, ImmutableMap.of( + "phoneNumber", phoneNumber, + "message", message + )); + } } /** * Emulate GSM call event on the connected emulator. * * @param phoneNumber The phone number of the caller. - * @param gsmCallActions One of available {@link GsmCallActions} values. + * @param gsmCallAction One of available {@link GsmCallActions} values. */ - default void makeGsmCall(String phoneNumber, GsmCallActions gsmCallActions) { - CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions)); + default void makeGsmCall(String phoneNumber, GsmCallActions gsmCallAction) { + try { + CommandExecutionHelper.executeScript(this, "mobile: gsmCall", ImmutableMap.of( + "phoneNumber", phoneNumber, + "action", gsmCallAction.toString().toLowerCase() + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(GSM_CALL, ImmutableMap.of( + "phoneNumber", phoneNumber, + "action", gsmCallAction.toString().toLowerCase() + )); + } } /** @@ -39,7 +63,17 @@ default void makeGsmCall(String phoneNumber, GsmCallActions gsmCallActions) { * @param gsmSignalStrength One of available {@link GsmSignalStrength} values. */ default void setGsmSignalStrength(GsmSignalStrength gsmSignalStrength) { - CommandExecutionHelper.execute(this, gsmSignalStrengthCommand(gsmSignalStrength)); + try { + CommandExecutionHelper.executeScript(this, "mobile: gsmSignal", ImmutableMap.of( + "strength", gsmSignalStrength.ordinal() + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(GSM_SIGNAL, ImmutableMap.of( + "signalStrengh", gsmSignalStrength.ordinal(), + "signalStrength", gsmSignalStrength.ordinal() + )); + } } /** @@ -48,7 +82,16 @@ default void setGsmSignalStrength(GsmSignalStrength gsmSignalStrength) { * @param gsmVoiceState One of available {@link GsmVoiceState} values. */ default void setGsmVoice(GsmVoiceState gsmVoiceState) { - CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState)); + try { + CommandExecutionHelper.executeScript(this, "mobile: gsmVoice", ImmutableMap.of( + "state", gsmVoiceState.toString().toLowerCase() + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(GSM_VOICE, ImmutableMap.of( + "state", gsmVoiceState.name().toLowerCase() + )); + } } /** @@ -57,7 +100,16 @@ default void setGsmVoice(GsmVoiceState gsmVoiceState) { * @param networkSpeed One of available {@link NetworkSpeed} values. */ default void setNetworkSpeed(NetworkSpeed networkSpeed) { - CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed)); + try { + CommandExecutionHelper.executeScript(this, "mobile: networkSpeed", ImmutableMap.of( + "speed", networkSpeed.toString().toLowerCase() + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(NETWORK_SPEED, ImmutableMap.of( + "netspeed", networkSpeed.name().toLowerCase() + )); + } } /** @@ -66,7 +118,16 @@ default void setNetworkSpeed(NetworkSpeed networkSpeed) { * @param percent Percentage value in range [0, 100]. */ default void setPowerCapacity(int percent) { - CommandExecutionHelper.execute(this, powerCapacityCommand(percent)); + try { + CommandExecutionHelper.executeScript(this, "mobile: powerCapacity", ImmutableMap.of( + "percent", percent + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(POWER_CAPACITY, ImmutableMap.of( + "percent", percent + )); + } } /** @@ -75,7 +136,16 @@ default void setPowerCapacity(int percent) { * @param powerACState One of available {@link PowerACState} values. */ default void setPowerAC(PowerACState powerACState) { - CommandExecutionHelper.execute(this, powerACCommand(powerACState)); + try { + CommandExecutionHelper.executeScript(this, "mobile: powerAC", ImmutableMap.of( + "state", powerACState.toString().toLowerCase() + )); + } catch (UnsupportedCommandException e) { + // TODO: Remove the fallback + this.execute(POWER_AC_STATE, ImmutableMap.of( + "state", powerACState.name().toLowerCase() + )); + } } } 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 aa2434d50..246951d8a 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -246,11 +246,6 @@ public void resetTest() { driver.resetApp(); } - @Test - public void endTestCoverage() { - driver.endTestCoverage("android.intent.action.MAIN", ""); - } - @Test public void deviceDetailsAndKeyboardTest() { assertFalse(driver.isKeyboardShown()); From 0050f0f534839b2651faf251eb200fa6949be1fc Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 28 Apr 2023 22:28:13 +0200 Subject: [PATCH 2/2] Fix syntax --- .../appium/java_client/android/AuthenticatesByFinger.java | 2 +- .../io/appium/java_client/android/StartsActivity.java | 2 -- .../android/SupportsSpecialEmulatorCommands.java | 8 ++++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java b/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java index 0d9abe90b..a9ecf128f 100644 --- a/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java +++ b/src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java @@ -17,7 +17,7 @@ public interface AuthenticatesByFinger extends ExecutesMethod { default void fingerPrint(int fingerPrintId) { try { CommandExecutionHelper.executeScript(this, "mobile: fingerprint", ImmutableMap.of( - "fingerprintId", fingerPrintId + "fingerprintId", fingerPrintId )); } catch (UnsupportedCommandException e) { // TODO: Remove the fallback diff --git a/src/main/java/io/appium/java_client/android/StartsActivity.java b/src/main/java/io/appium/java_client/android/StartsActivity.java index 8881ff629..9291e5020 100644 --- a/src/main/java/io/appium/java_client/android/StartsActivity.java +++ b/src/main/java/io/appium/java_client/android/StartsActivity.java @@ -27,8 +27,6 @@ import static io.appium.java_client.MobileCommand.CURRENT_ACTIVITY; import static io.appium.java_client.MobileCommand.GET_CURRENT_PACKAGE; -import static io.appium.java_client.android.AndroidMobileCommandHelper.currentActivityCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.currentPackageCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.startActivityCommand; public interface StartsActivity extends ExecutesMethod { diff --git a/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java index 83f0c48b7..29cd6415e 100644 --- a/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java +++ b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java @@ -24,8 +24,8 @@ public interface SupportsSpecialEmulatorCommands extends ExecutesMethod { default void sendSMS(String phoneNumber, String message) { try { CommandExecutionHelper.executeScript(this, "mobile: sendSms", ImmutableMap.of( - "phoneNumber", phoneNumber, - "message", message + "phoneNumber", phoneNumber, + "message", message )); } catch (UnsupportedCommandException e) { // TODO: Remove the fallback @@ -65,7 +65,7 @@ default void makeGsmCall(String phoneNumber, GsmCallActions gsmCallAction) { default void setGsmSignalStrength(GsmSignalStrength gsmSignalStrength) { try { CommandExecutionHelper.executeScript(this, "mobile: gsmSignal", ImmutableMap.of( - "strength", gsmSignalStrength.ordinal() + "strength", gsmSignalStrength.ordinal() )); } catch (UnsupportedCommandException e) { // TODO: Remove the fallback @@ -102,7 +102,7 @@ default void setGsmVoice(GsmVoiceState gsmVoiceState) { default void setNetworkSpeed(NetworkSpeed networkSpeed) { try { CommandExecutionHelper.executeScript(this, "mobile: networkSpeed", ImmutableMap.of( - "speed", networkSpeed.toString().toLowerCase() + "speed", networkSpeed.toString().toLowerCase() )); } catch (UnsupportedCommandException e) { // TODO: Remove the fallback