From dc8e3eb942379e2a3b02fa2eb4f371d90f0c5496 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 17 Feb 2018 15:15:36 +0530 Subject: [PATCH 1/5] Add handlers for gsm, network, power and sms command --- .../io/appium/java_client/MobileCommand.java | 21 ++++ .../java_client/android/AndroidDriver.java | 71 ++++++++++++ .../android/AndroidMobileCommandHelper.java | 105 ++++++++++++++++++ .../java_client/android/GsmCallActions.java | 18 +++ .../android/GsmSignalStrength.java | 17 +++ .../java_client/android/GsmVoiceState.java | 21 ++++ .../java_client/android/NetworkSpeed.java | 23 ++++ .../java_client/android/PowerACState.java | 16 +++ .../android/AndroidDriverTest.java | 28 +++++ 9 files changed, 320 insertions(+) create mode 100644 src/main/java/io/appium/java_client/android/GsmCallActions.java create mode 100644 src/main/java/io/appium/java_client/android/GsmSignalStrength.java create mode 100644 src/main/java/io/appium/java_client/android/GsmVoiceState.java create mode 100644 src/main/java/io/appium/java_client/android/NetworkSpeed.java create mode 100644 src/main/java/io/appium/java_client/android/PowerACState.java diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index c58997068..bba0a77aa 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -85,6 +85,13 @@ public class MobileCommand { protected static final String GET_SETTINGS; protected static final String SET_SETTINGS; protected static final String GET_CURRENT_PACKAGE; + protected static final String SEND_SMS; + protected static final String GSM_CALL; + protected static final String GSM_SIGNAL; + protected static final String GSM_VOICE; + protected static final String NETWORK_SPEED; + protected static final String POWER_CAPACITY; + protected static final String POWER_AC_STATE; public static final Map commandRepository; @@ -137,6 +144,13 @@ public class MobileCommand { GET_SETTINGS = "getSettings"; SET_SETTINGS = "setSettings"; GET_CURRENT_PACKAGE = "getCurrentPackage"; + SEND_SMS = "sendSMS"; + GSM_CALL = "gsmCall"; + GSM_SIGNAL = "gsmSignal"; + GSM_VOICE = "gsmVoice"; + NETWORK_SPEED = "networkSpeed"; + POWER_CAPACITY = "powerCapacity"; + POWER_AC_STATE = "powerAC"; commandRepository = new HashMap<>(); commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset")); @@ -198,6 +212,13 @@ public class MobileCommand { commandRepository.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock")); commandRepository.put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value")); commandRepository.put(GET_CURRENT_PACKAGE, getC("/session/:sessionId/appium/device/current_package")); + commandRepository.put(SEND_SMS, postC("/session/:sessionId/appium/device/send_sms")); + commandRepository.put(GSM_CALL, postC("/session/:sessionId/appium/device/gsm_call")); + commandRepository.put(GSM_SIGNAL, postC("/session/:sessionId/appium/device/gsm_signal")); + commandRepository.put(GSM_VOICE, postC("/session/:sessionId/appium/device/gsm_voice")); + commandRepository.put(NETWORK_SPEED, postC("/session/:sessionId/appium/device/network_speed")); + commandRepository.put(POWER_CAPACITY, postC("/session/:sessionId/appium/device/power_capacity")); + commandRepository.put(POWER_AC_STATE, postC("/session/:sessionId/appium/device/power_ac")); } /** 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 8b822337d..74062788d 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -17,7 +17,14 @@ package io.appium.java_client.android; import static io.appium.java_client.android.AndroidMobileCommandHelper.endTestCoverageCommand; +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.openNotificationsCommand; +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.android.AndroidMobileCommandHelper.toggleLocationServicesCommand; import io.appium.java_client.AppiumDriver; @@ -176,4 +183,68 @@ public void toggleLocationServices() { CommandExecutionHelper.execute(this, toggleLocationServicesCommand()); } + /** + * Emulate send SMS event on the connected emulator. + * + * @param phoneNumber The phone number of message sender. + * @param message The message content. + */ + public void sendSMS(String phoneNumber, String message) { + CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message)); + } + + /** + * Emulate GSM call event on the connected emulator. + * + * @param phoneNumber The phone number of the caller. + * @param gsmCallActions One of available GSM call actions. + */ + public void gsmCall(String phoneNumber, GsmCallActions gsmCallActions) { + CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions)); + } + + /** + * Emulate GSM signal strength change event on the connected emulator. + * + * @param gsmSignalStrength One of available GSM signal strength. + */ + public void gsmSignalStrength(GsmSignalStrength gsmSignalStrength) { + CommandExecutionHelper.execute(this, gsmSignalStrengthCommand(gsmSignalStrength)); + } + + /** + * Emulate GSM voice event on the connected emulator. + * + * @param gsmVoiceState One of available GSM voice state. + */ + public void gsmVoice(GsmVoiceState gsmVoiceState) { + CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState)); + } + + /** + * Emulate network speed change event on the connected emulator. + * + * @param networkSpeed One of available Network Speed values. + */ + public void networkSpeed(NetworkSpeed networkSpeed) { + CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed)); + } + + /** + * Emulate power capacity change on the connected emulator. + * + * @param percent Percentage value in range [0, 100]. + */ + public void powerCapacity(int percent) { + CommandExecutionHelper.execute(this, powerCapacityCommand(percent)); + } + + /** + * Emulate power state change on the connected emulator. + * + * @param powerACState One of available Power AC state. + */ + public void powerAC(PowerACState powerACState) { + CommandExecutionHelper.execute(this, powerACCommand(powerACState)); + } } 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 c82c324a4..be341eea2 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -291,4 +291,109 @@ public class AndroidMobileCommandHelper extends MobileCommand { return new AbstractMap.SimpleEntry<>( REPLACE_VALUE, prepareArguments(parameters, values)); } + + /** + * This method forms a {@link Map} of parameters for the element + * value replacement. It is used against input elements + * + * @param phoneNumber The phone number of message sender + * @param message The message content + * + * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. + */ + public static Map.Entry> sendSMSCommand( + String phoneNumber, String message) { + ImmutableMap parameters = ImmutableMap + .builder().put("phoneNumber", phoneNumber) + .put("message", message) + .build(); + + return new AbstractMap.SimpleEntry<>(SEND_SMS, parameters); + } + + /** + * This method forms a {@link Map} of parameters for the element + * value replacement. It is used against input elements + * + * @param phoneNumber The phone number of message sender + * @param gsmCallActions One of available GSM call actions + * + * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. + */ + public static Map.Entry> gsmCallCommand( + String phoneNumber, GsmCallActions gsmCallActions) { + String[] parameters = new String[] {"phoneNumber", "action"}; + Object[] values = new Object[]{phoneNumber, gsmCallActions.toString()}; + return new AbstractMap.SimpleEntry<>(GSM_CALL, prepareArguments(parameters, values)); + } + + /** + * This method forms a {@link Map} of parameters for the element + * value replacement. It is used against input elements + * + * @param gsmSignalStrength One of available GSM signal strength + * + * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. + */ + public static Map.Entry> gsmSignalStrengthCommand( + GsmSignalStrength gsmSignalStrength) { + return new AbstractMap.SimpleEntry<>(GSM_SIGNAL, + prepareArguments("signalStrengh", gsmSignalStrength.getValue())); + } + + /** + * This method forms a {@link Map} of parameters for the element + * value replacement. It is used against input elements + * + * @param gsmVoiceState One of available GSM voice state + * + * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. + */ + public static Map.Entry> gsmVoiceCommand( + GsmVoiceState gsmVoiceState) { + return new AbstractMap.SimpleEntry<>(GSM_VOICE, + prepareArguments("state", gsmVoiceState.toString())); + } + + /** + * This method forms a {@link Map} of parameters for the element + * value replacement. It is used against input elements + * + * @param networkSpeed One of possible NETWORK_SPEED values + * + * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. + */ + public static Map.Entry> networkSpeedCommand( + NetworkSpeed networkSpeed) { + return new AbstractMap.SimpleEntry<>(NETWORK_SPEED, + prepareArguments("netspeed", networkSpeed.toString())); + } + + /** + * This method forms a {@link Map} of parameters for the element + * value replacement. It is used against input elements + * + * @param percent A number in range [0, 4] + * + * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. + */ + public static Map.Entry> powerCapacityCommand( + int percent) { + return new AbstractMap.SimpleEntry<>(POWER_CAPACITY, + prepareArguments("percent", percent)); + } + + /** + * This method forms a {@link Map} of parameters for the element + * value replacement. It is used against input elements + * + * @param powerACState One of available power AC state + * + * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. + */ + public static Map.Entry> powerACCommand( + PowerACState powerACState) { + return new AbstractMap.SimpleEntry<>(POWER_AC_STATE, + prepareArguments("state", powerACState.toString())); + } } diff --git a/src/main/java/io/appium/java_client/android/GsmCallActions.java b/src/main/java/io/appium/java_client/android/GsmCallActions.java new file mode 100644 index 000000000..e9afefdf5 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/GsmCallActions.java @@ -0,0 +1,18 @@ +package io.appium.java_client.android; + +public enum GsmCallActions { + CALL("call"), + ACCEPT("accept"), + CANCEL("cancel"), + HOLD("hold"); + + private final String gsmcall; + + GsmCallActions(String gsmcall) { + this.gsmcall = gsmcall; + } + + @Override public String toString() { + return this.gsmcall; + } +} diff --git a/src/main/java/io/appium/java_client/android/GsmSignalStrength.java b/src/main/java/io/appium/java_client/android/GsmSignalStrength.java new file mode 100644 index 000000000..8097ea241 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/GsmSignalStrength.java @@ -0,0 +1,17 @@ +package io.appium.java_client.android; + +public enum GsmSignalStrength { + NONE_OR_UNKNOWN(0), + POOR(1), + MODERATE(2), + GOOD(3), + GREAT(4); + + private final int gsmSignalStrength; + + GsmSignalStrength(int gsmSignalStrength) { + this.gsmSignalStrength = gsmSignalStrength; + } + + public int getValue() { return gsmSignalStrength; } +} diff --git a/src/main/java/io/appium/java_client/android/GsmVoiceState.java b/src/main/java/io/appium/java_client/android/GsmVoiceState.java new file mode 100644 index 000000000..a93e76a5f --- /dev/null +++ b/src/main/java/io/appium/java_client/android/GsmVoiceState.java @@ -0,0 +1,21 @@ +package io.appium.java_client.android; + +public enum GsmVoiceState { + ON("on"), + OFF("off"), + DENIED("denied"), + SEARCHING("searching"), + ROAMING("roaming"), + HOME("home"), + UNREGISTERED("unregistered"); + + private final String gsmVoiceState; + + GsmVoiceState(String gsmVoiceState) { + this.gsmVoiceState = gsmVoiceState; + } + + @Override public String toString() { + return this.gsmVoiceState; + } +} diff --git a/src/main/java/io/appium/java_client/android/NetworkSpeed.java b/src/main/java/io/appium/java_client/android/NetworkSpeed.java new file mode 100644 index 000000000..7c3bb215e --- /dev/null +++ b/src/main/java/io/appium/java_client/android/NetworkSpeed.java @@ -0,0 +1,23 @@ +package io.appium.java_client.android; + +public enum NetworkSpeed { + GSM("gsm"), + SCSD("scsd"), + GPRS("gprs"), + EDGE("edge"), + UMTS("umts"), + HSDPA("hsdpa"), + LTE("lte"), + EVDO("evdo"), + FULL("full"); + + private final String networkSpeed; + + NetworkSpeed(String networkSpeed) { + this.networkSpeed = networkSpeed; + } + + @Override public String toString() { + return this.networkSpeed; + } +} diff --git a/src/main/java/io/appium/java_client/android/PowerACState.java b/src/main/java/io/appium/java_client/android/PowerACState.java new file mode 100644 index 000000000..39eb1059f --- /dev/null +++ b/src/main/java/io/appium/java_client/android/PowerACState.java @@ -0,0 +1,16 @@ +package io.appium.java_client.android; + +public enum PowerACState { + ON("on"), + OFF("off"); + + private final String powerACState; + + PowerACState(String powerACState) { + this.powerACState = powerACState; + } + + @Override public String toString() { + return this.powerACState; + } +} 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 acbf1adb2..c89ab51a3 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -37,6 +37,34 @@ public class AndroidDriverTest extends BaseAndroidTest { + @Test public void sendSMSTest() { + driver.sendSMS("11111111", "call"); + } + + @Test public void gsmCallTest() { + driver.gsmCall("11111111", GsmCallActions.CALL); + driver.gsmCall("11111111", GsmCallActions.ACCEPT); + } + + @Test public void gsmSignalStrengthTest() { + driver.gsmSignalStrength(GsmSignalStrength.GREAT); + } + + @Test public void gsmVoiceTest() { + driver.gsmVoice(GsmVoiceState.OFF); + } + + @Test public void networkSpeedTest() { + driver.networkSpeed(NetworkSpeed.LTE); + driver.powerCapacity(50); + driver.powerAC(PowerACState.ON); + } + + @Test public void powerTest() { + driver.powerCapacity(50); + driver.powerAC(PowerACState.ON); + } + @Test public void getDeviceTimeTest() { String time = driver.getDeviceTime(); assertTrue(time.length() == 28); From 0fdc02868c70a2dc8a3c1cd93e8fe4ca8b32a687 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 17 Feb 2018 23:30:37 +0530 Subject: [PATCH 2/5] fixed review comments --- .../java_client/android/AndroidDriver.java | 75 +---------------- .../android/AndroidMobileCommandHelper.java | 24 +++--- .../java_client/android/GsmCallActions.java | 15 +--- .../android/GsmSignalStrength.java | 14 +--- .../java_client/android/GsmVoiceState.java | 18 +---- .../java_client/android/NetworkSpeed.java | 20 +---- .../java_client/android/PowerACState.java | 13 +-- .../SupportsSpecialEmulatorCommands.java | 81 +++++++++++++++++++ .../android/AndroidDriverTest.java | 8 +- 9 files changed, 103 insertions(+), 165 deletions(-) create mode 100644 src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java 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 74062788d..d676cfb93 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -17,14 +17,7 @@ package io.appium.java_client.android; import static io.appium.java_client.android.AndroidMobileCommandHelper.endTestCoverageCommand; -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.openNotificationsCommand; -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.android.AndroidMobileCommandHelper.toggleLocationServicesCommand; import io.appium.java_client.AppiumDriver; @@ -58,7 +51,8 @@ public class AndroidDriver extends AppiumDriver implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity, FindsByAndroidUIAutomator, LocksDevice, HasAndroidSettings, HasDeviceDetails, - HasSupportedPerformanceDataType, AuthenticatesByFinger, CanRecordScreen { + HasSupportedPerformanceDataType, AuthenticatesByFinger, + CanRecordScreen, SupportsSpecialEmulatorCommands { private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID; @@ -182,69 +176,4 @@ public void openNotifications() { public void toggleLocationServices() { CommandExecutionHelper.execute(this, toggleLocationServicesCommand()); } - - /** - * Emulate send SMS event on the connected emulator. - * - * @param phoneNumber The phone number of message sender. - * @param message The message content. - */ - public void sendSMS(String phoneNumber, String message) { - CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message)); - } - - /** - * Emulate GSM call event on the connected emulator. - * - * @param phoneNumber The phone number of the caller. - * @param gsmCallActions One of available GSM call actions. - */ - public void gsmCall(String phoneNumber, GsmCallActions gsmCallActions) { - CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions)); - } - - /** - * Emulate GSM signal strength change event on the connected emulator. - * - * @param gsmSignalStrength One of available GSM signal strength. - */ - public void gsmSignalStrength(GsmSignalStrength gsmSignalStrength) { - CommandExecutionHelper.execute(this, gsmSignalStrengthCommand(gsmSignalStrength)); - } - - /** - * Emulate GSM voice event on the connected emulator. - * - * @param gsmVoiceState One of available GSM voice state. - */ - public void gsmVoice(GsmVoiceState gsmVoiceState) { - CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState)); - } - - /** - * Emulate network speed change event on the connected emulator. - * - * @param networkSpeed One of available Network Speed values. - */ - public void networkSpeed(NetworkSpeed networkSpeed) { - CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed)); - } - - /** - * Emulate power capacity change on the connected emulator. - * - * @param percent Percentage value in range [0, 100]. - */ - public void powerCapacity(int percent) { - CommandExecutionHelper.execute(this, powerCapacityCommand(percent)); - } - - /** - * Emulate power state change on the connected emulator. - * - * @param powerACState One of available Power AC state. - */ - public void powerAC(PowerACState powerACState) { - CommandExecutionHelper.execute(this, powerACCommand(powerACState)); - } } 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 be341eea2..5066ce2a6 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -301,7 +301,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. */ - public static Map.Entry> sendSMSCommand( + public static Map.Entry> sendSMSCommand( String phoneNumber, String message) { ImmutableMap parameters = ImmutableMap .builder().put("phoneNumber", phoneNumber) @@ -320,10 +320,10 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ - public static Map.Entry> gsmCallCommand( + public static Map.Entry> gsmCallCommand( String phoneNumber, GsmCallActions gsmCallActions) { String[] parameters = new String[] {"phoneNumber", "action"}; - Object[] values = new Object[]{phoneNumber, gsmCallActions.toString()}; + Object[] values = new Object[]{phoneNumber, gsmCallActions.name().toLowerCase()}; return new AbstractMap.SimpleEntry<>(GSM_CALL, prepareArguments(parameters, values)); } @@ -335,10 +335,10 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ - public static Map.Entry> gsmSignalStrengthCommand( + public static Map.Entry> gsmSignalStrengthCommand( GsmSignalStrength gsmSignalStrength) { return new AbstractMap.SimpleEntry<>(GSM_SIGNAL, - prepareArguments("signalStrengh", gsmSignalStrength.getValue())); + prepareArguments("signalStrengh", gsmSignalStrength.ordinal())); } /** @@ -349,10 +349,10 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ - public static Map.Entry> gsmVoiceCommand( + public static Map.Entry> gsmVoiceCommand( GsmVoiceState gsmVoiceState) { return new AbstractMap.SimpleEntry<>(GSM_VOICE, - prepareArguments("state", gsmVoiceState.toString())); + prepareArguments("state", gsmVoiceState.name().toLowerCase())); } /** @@ -363,10 +363,10 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ - public static Map.Entry> networkSpeedCommand( + public static Map.Entry> networkSpeedCommand( NetworkSpeed networkSpeed) { return new AbstractMap.SimpleEntry<>(NETWORK_SPEED, - prepareArguments("netspeed", networkSpeed.toString())); + prepareArguments("netspeed", networkSpeed.name().toLowerCase())); } /** @@ -377,7 +377,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. */ - public static Map.Entry> powerCapacityCommand( + public static Map.Entry> powerCapacityCommand( int percent) { return new AbstractMap.SimpleEntry<>(POWER_CAPACITY, prepareArguments("percent", percent)); @@ -391,9 +391,9 @@ public class AndroidMobileCommandHelper extends MobileCommand { * * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments. */ - public static Map.Entry> powerACCommand( + public static Map.Entry> powerACCommand( PowerACState powerACState) { return new AbstractMap.SimpleEntry<>(POWER_AC_STATE, - prepareArguments("state", powerACState.toString())); + prepareArguments("state", powerACState.name().toLowerCase())); } } diff --git a/src/main/java/io/appium/java_client/android/GsmCallActions.java b/src/main/java/io/appium/java_client/android/GsmCallActions.java index e9afefdf5..443d85a09 100644 --- a/src/main/java/io/appium/java_client/android/GsmCallActions.java +++ b/src/main/java/io/appium/java_client/android/GsmCallActions.java @@ -1,18 +1,5 @@ package io.appium.java_client.android; public enum GsmCallActions { - CALL("call"), - ACCEPT("accept"), - CANCEL("cancel"), - HOLD("hold"); - - private final String gsmcall; - - GsmCallActions(String gsmcall) { - this.gsmcall = gsmcall; - } - - @Override public String toString() { - return this.gsmcall; - } + CALL, ACCEPT, CANCEL, HOLD } diff --git a/src/main/java/io/appium/java_client/android/GsmSignalStrength.java b/src/main/java/io/appium/java_client/android/GsmSignalStrength.java index 8097ea241..a73513df2 100644 --- a/src/main/java/io/appium/java_client/android/GsmSignalStrength.java +++ b/src/main/java/io/appium/java_client/android/GsmSignalStrength.java @@ -1,17 +1,5 @@ package io.appium.java_client.android; public enum GsmSignalStrength { - NONE_OR_UNKNOWN(0), - POOR(1), - MODERATE(2), - GOOD(3), - GREAT(4); - - private final int gsmSignalStrength; - - GsmSignalStrength(int gsmSignalStrength) { - this.gsmSignalStrength = gsmSignalStrength; - } - - public int getValue() { return gsmSignalStrength; } + NONE_OR_UNKNOWN, POOR, MODERATE, GOOD, GREAT } diff --git a/src/main/java/io/appium/java_client/android/GsmVoiceState.java b/src/main/java/io/appium/java_client/android/GsmVoiceState.java index a93e76a5f..e92cde951 100644 --- a/src/main/java/io/appium/java_client/android/GsmVoiceState.java +++ b/src/main/java/io/appium/java_client/android/GsmVoiceState.java @@ -1,21 +1,5 @@ package io.appium.java_client.android; public enum GsmVoiceState { - ON("on"), - OFF("off"), - DENIED("denied"), - SEARCHING("searching"), - ROAMING("roaming"), - HOME("home"), - UNREGISTERED("unregistered"); - - private final String gsmVoiceState; - - GsmVoiceState(String gsmVoiceState) { - this.gsmVoiceState = gsmVoiceState; - } - - @Override public String toString() { - return this.gsmVoiceState; - } + ON, OFF, DENIED, SEARCHING, ROAMING, HOME, UNREGISTERED } diff --git a/src/main/java/io/appium/java_client/android/NetworkSpeed.java b/src/main/java/io/appium/java_client/android/NetworkSpeed.java index 7c3bb215e..64cdc513d 100644 --- a/src/main/java/io/appium/java_client/android/NetworkSpeed.java +++ b/src/main/java/io/appium/java_client/android/NetworkSpeed.java @@ -1,23 +1,5 @@ package io.appium.java_client.android; public enum NetworkSpeed { - GSM("gsm"), - SCSD("scsd"), - GPRS("gprs"), - EDGE("edge"), - UMTS("umts"), - HSDPA("hsdpa"), - LTE("lte"), - EVDO("evdo"), - FULL("full"); - - private final String networkSpeed; - - NetworkSpeed(String networkSpeed) { - this.networkSpeed = networkSpeed; - } - - @Override public String toString() { - return this.networkSpeed; - } + GSM, SCSD, GPRS, EDGE, UMTS, HSDPA, LTE, EVDO, FULL } diff --git a/src/main/java/io/appium/java_client/android/PowerACState.java b/src/main/java/io/appium/java_client/android/PowerACState.java index 39eb1059f..ab845c925 100644 --- a/src/main/java/io/appium/java_client/android/PowerACState.java +++ b/src/main/java/io/appium/java_client/android/PowerACState.java @@ -1,16 +1,5 @@ package io.appium.java_client.android; public enum PowerACState { - ON("on"), - OFF("off"); - - private final String powerACState; - - PowerACState(String powerACState) { - this.powerACState = powerACState; - } - - @Override public String toString() { - return this.powerACState; - } + ON, OFF } diff --git a/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java new file mode 100644 index 000000000..1f3bb6075 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java @@ -0,0 +1,81 @@ +package io.appium.java_client.android; + +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 io.appium.java_client.CommandExecutionHelper; +import io.appium.java_client.ExecutesMethod; + +public interface SupportsSpecialEmulatorCommands extends ExecutesMethod { + + /** + * Emulate send SMS event on the connected emulator. + * + * @param phoneNumber The phone number of message sender. + * @param message The message content. + */ + default void sendSMS(String phoneNumber, String message) { + CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message)); + } + + /** + * Emulate GSM call event on the connected emulator. + * + * @param phoneNumber The phone number of the caller. + * @param gsmCallActions One of available GSM call actions {@link GsmCallActions}. + */ + default void gsmCall(String phoneNumber, GsmCallActions gsmCallActions) { + CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions)); + } + + /** + * Emulate GSM signal strength change event on the connected emulator. + * + * @param gsmSignalStrength One of available GSM signal strength {@link GsmSignalStrength}. + */ + default void gsmSignalStrength(GsmSignalStrength gsmSignalStrength) { + CommandExecutionHelper.execute( this, gsmSignalStrengthCommand(gsmSignalStrength)); + } + + /** + * Emulate GSM voice event on the connected emulator. + * + * @param gsmVoiceState One of available GSM voice state {@link GsmVoiceState}. + */ + default void gsmVoice(GsmVoiceState gsmVoiceState) { + CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState)); + } + + /** + * Emulate network speed change event on the connected emulator. + * + * @param networkSpeed One of available Network Speed values {@link NetworkSpeed}. + */ + default void networkSpeed(NetworkSpeed networkSpeed) { + CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed)); + } + + /** + * Emulate power capacity change on the connected emulator. + * + * @param percent Percentage value in range [0, 100]. + */ + default void powerCapacity(int percent) { + CommandExecutionHelper.execute(this, powerCapacityCommand(percent)); + } + + /** + * Emulate power state change on the connected emulator. + * + * @param powerACState One of available Power AC state {@link PowerACState}. + */ + default void powerAC(PowerACState powerACState) { + CommandExecutionHelper.execute(this, powerACCommand(powerACState)); + } + +} 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 c89ab51a3..ee5d652b7 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -55,14 +55,12 @@ public class AndroidDriverTest extends BaseAndroidTest { } @Test public void networkSpeedTest() { - driver.networkSpeed(NetworkSpeed.LTE); - driver.powerCapacity(50); - driver.powerAC(PowerACState.ON); + driver.networkSpeed(NetworkSpeed.EDGE); } @Test public void powerTest() { - driver.powerCapacity(50); - driver.powerAC(PowerACState.ON); + driver.powerCapacity(100); + driver.powerAC(PowerACState.OFF); } @Test public void getDeviceTimeTest() { From 21660637d67d6524eddc7c7eb4a82c45f4ab599c Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 18 Feb 2018 15:09:17 +0530 Subject: [PATCH 3/5] make codacy happy --- .../SupportsSpecialEmulatorCommands.java | 22 +++++----- .../android/AndroidDriverTest.java | 40 +++++++++++++++---- 2 files changed, 43 insertions(+), 19 deletions(-) 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 1f3bb6075..6041c0380 100644 --- a/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java +++ b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java @@ -27,36 +27,36 @@ default void sendSMS(String phoneNumber, String message) { * Emulate GSM call event on the connected emulator. * * @param phoneNumber The phone number of the caller. - * @param gsmCallActions One of available GSM call actions {@link GsmCallActions}. + * @param gsmCallActions One of available {@link GsmCallActions} values. */ - default void gsmCall(String phoneNumber, GsmCallActions gsmCallActions) { + default void setGsmCall(String phoneNumber, GsmCallActions gsmCallActions) { CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions)); } /** * Emulate GSM signal strength change event on the connected emulator. * - * @param gsmSignalStrength One of available GSM signal strength {@link GsmSignalStrength}. + * @param gsmSignalStrength One of available {@link GsmSignalStrength} values. */ - default void gsmSignalStrength(GsmSignalStrength gsmSignalStrength) { + default void setGsmSignalStrength(GsmSignalStrength gsmSignalStrength) { CommandExecutionHelper.execute( this, gsmSignalStrengthCommand(gsmSignalStrength)); } /** * Emulate GSM voice event on the connected emulator. * - * @param gsmVoiceState One of available GSM voice state {@link GsmVoiceState}. + * @param gsmVoiceState One of available {@link GsmVoiceState} values. */ - default void gsmVoice(GsmVoiceState gsmVoiceState) { + default void setGsmVoice(GsmVoiceState gsmVoiceState) { CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState)); } /** * Emulate network speed change event on the connected emulator. * - * @param networkSpeed One of available Network Speed values {@link NetworkSpeed}. + * @param networkSpeed One of available {@link NetworkSpeed} values. */ - default void networkSpeed(NetworkSpeed networkSpeed) { + default void setNetworkSpeed(NetworkSpeed networkSpeed) { CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed)); } @@ -65,16 +65,16 @@ default void networkSpeed(NetworkSpeed networkSpeed) { * * @param percent Percentage value in range [0, 100]. */ - default void powerCapacity(int percent) { + default void setPowerCapacity(int percent) { CommandExecutionHelper.execute(this, powerCapacityCommand(percent)); } /** * Emulate power state change on the connected emulator. * - * @param powerACState One of available Power AC state {@link PowerACState}. + * @param powerACState One of available {@link PowerACState} values. */ - default void powerAC(PowerACState powerACState) { + default void setPowerAC(PowerACState powerACState) { CommandExecutionHelper.execute(this, powerACCommand(powerACState)); } 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 ee5d652b7..e0f9f1e97 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -38,29 +38,53 @@ public class AndroidDriverTest extends BaseAndroidTest { @Test public void sendSMSTest() { - driver.sendSMS("11111111", "call"); + try { + driver.sendSMS("11111111", "call"); + } catch (Exception e) { + assertFalse( "method works only in emulators", true); + } } @Test public void gsmCallTest() { - driver.gsmCall("11111111", GsmCallActions.CALL); - driver.gsmCall("11111111", GsmCallActions.ACCEPT); + try { + driver.setGsmCall("11111111", GsmCallActions.CALL); + driver.setGsmCall("11111111", GsmCallActions.ACCEPT); + } catch (Exception e) { + assertFalse( "method works only in emulators", true); + } } @Test public void gsmSignalStrengthTest() { - driver.gsmSignalStrength(GsmSignalStrength.GREAT); + try { + driver.setGsmSignalStrength(GsmSignalStrength.GREAT); + } catch (Exception e) { + assertFalse( "method works only in emulators", true); + } } @Test public void gsmVoiceTest() { - driver.gsmVoice(GsmVoiceState.OFF); + try { + driver.setGsmVoice(GsmVoiceState.OFF); + } catch (Exception e) { + assertFalse( "method works only in emulators", true); + } } @Test public void networkSpeedTest() { - driver.networkSpeed(NetworkSpeed.EDGE); + try { + driver.setNetworkSpeed(NetworkSpeed.EDGE); + } catch (Exception e) { + assertFalse( "method works only in emulators", true); + } } @Test public void powerTest() { - driver.powerCapacity(100); - driver.powerAC(PowerACState.OFF); + try { + driver.setPowerCapacity(100); + driver.setPowerAC(PowerACState.OFF); + } catch (Exception e) { + assertFalse( "method works only in emulators", true); + } } @Test public void getDeviceTimeTest() { From 52bb05edc3d8b004782effe73fc45aa6ba3bfec4 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 18 Feb 2018 15:42:09 +0530 Subject: [PATCH 4/5] update as per review comments --- .../java_client/android/AndroidDriverTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 e0f9f1e97..4131f3ac3 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; @@ -41,7 +42,7 @@ public class AndroidDriverTest extends BaseAndroidTest { try { driver.sendSMS("11111111", "call"); } catch (Exception e) { - assertFalse( "method works only in emulators", true); + fail("method works only in emulators"); } } @@ -50,7 +51,7 @@ public class AndroidDriverTest extends BaseAndroidTest { driver.setGsmCall("11111111", GsmCallActions.CALL); driver.setGsmCall("11111111", GsmCallActions.ACCEPT); } catch (Exception e) { - assertFalse( "method works only in emulators", true); + fail("method works only in emulators"); } } @@ -58,7 +59,7 @@ public class AndroidDriverTest extends BaseAndroidTest { try { driver.setGsmSignalStrength(GsmSignalStrength.GREAT); } catch (Exception e) { - assertFalse( "method works only in emulators", true); + fail("method works only in emulators"); } } @@ -66,7 +67,7 @@ public class AndroidDriverTest extends BaseAndroidTest { try { driver.setGsmVoice(GsmVoiceState.OFF); } catch (Exception e) { - assertFalse( "method works only in emulators", true); + fail("method works only in emulators"); } } @@ -74,7 +75,7 @@ public class AndroidDriverTest extends BaseAndroidTest { try { driver.setNetworkSpeed(NetworkSpeed.EDGE); } catch (Exception e) { - assertFalse( "method works only in emulators", true); + fail("method works only in emulators"); } } @@ -83,7 +84,7 @@ public class AndroidDriverTest extends BaseAndroidTest { driver.setPowerCapacity(100); driver.setPowerAC(PowerACState.OFF); } catch (Exception e) { - assertFalse( "method works only in emulators", true); + fail("method works only in emulators"); } } From 9e7610701bd12e69a980a2c7c416ca9f9ea9a05f Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 18 Feb 2018 21:38:21 +0530 Subject: [PATCH 5/5] Fixed review comments --- .../java_client/android/SupportsSpecialEmulatorCommands.java | 4 ++-- .../java/io/appium/java_client/android/AndroidDriverTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 6041c0380..9da6dfaec 100644 --- a/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java +++ b/src/main/java/io/appium/java_client/android/SupportsSpecialEmulatorCommands.java @@ -29,7 +29,7 @@ default void sendSMS(String phoneNumber, String message) { * @param phoneNumber The phone number of the caller. * @param gsmCallActions One of available {@link GsmCallActions} values. */ - default void setGsmCall(String phoneNumber, GsmCallActions gsmCallActions) { + default void makeGsmCall(String phoneNumber, GsmCallActions gsmCallActions) { CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions)); } @@ -39,7 +39,7 @@ default void setGsmCall(String phoneNumber, GsmCallActions gsmCallActions) { * @param gsmSignalStrength One of available {@link GsmSignalStrength} values. */ default void setGsmSignalStrength(GsmSignalStrength gsmSignalStrength) { - CommandExecutionHelper.execute( this, gsmSignalStrengthCommand(gsmSignalStrength)); + CommandExecutionHelper.execute(this, gsmSignalStrengthCommand(gsmSignalStrength)); } /** 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 4131f3ac3..91292742e 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -48,8 +48,8 @@ public class AndroidDriverTest extends BaseAndroidTest { @Test public void gsmCallTest() { try { - driver.setGsmCall("11111111", GsmCallActions.CALL); - driver.setGsmCall("11111111", GsmCallActions.ACCEPT); + driver.makeGsmCall("11111111", GsmCallActions.CALL); + driver.makeGsmCall("11111111", GsmCallActions.ACCEPT); } catch (Exception e) { fail("method works only in emulators"); }