-
-
Notifications
You must be signed in to change notification settings - Fork 768
Add handlers for gsm, network, power and sms command #834
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
Changes from 1 commit
dc8e3eb
0fdc028
2166063
52bb05e
9e76107
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<String, Map<String, ?>> sendSMSCommand( | ||
String phoneNumber, String message) { | ||
ImmutableMap<String, ?> parameters = ImmutableMap | ||
.<String, Object>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<String, Map<String, ?>> 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<String, Map<String, ?>> 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<String, Map<String, ?>> 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<String, Map<String, ?>> 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<String, Map<String, ?>> 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<String, Map<String, ?>> powerACCommand( | ||
|
||
PowerACState powerACState) { | ||
return new AbstractMap.SimpleEntry<>(POWER_AC_STATE, | ||
prepareArguments("state", powerACState.toString())); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather put these methods into separate interface named as
SupportsSpecialEmulatorCommands