Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CommandInfo> commandRepository;

Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
}

/**
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/io/appium/java_client/android/AndroidDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -176,4 +183,68 @@ public void toggleLocationServices() {
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
}

/**
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Feb 17, 2018

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

* 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.
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 put a direct link to the corresponding enum here

*/
public void powerAC(PowerACState powerACState) {
CommandExecutionHelper.execute(this, powerACCommand(powerACState));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Feb 17, 2018

Choose a reason for hiding this comment

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

all these methods have one extra space between the return type and the method name

PowerACState powerACState) {
return new AbstractMap.SimpleEntry<>(POWER_AC_STATE,
prepareArguments("state", powerACState.toString()));
}
}
18 changes: 18 additions & 0 deletions src/main/java/io/appium/java_client/android/GsmCallActions.java
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this constructor is redundant. All enum elements have name() and ordinal() properties. That's pretty all you need. Same comment to other enums

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; }
}
21 changes: 21 additions & 0 deletions src/main/java/io/appium/java_client/android/GsmVoiceState.java
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;
}
}
23 changes: 23 additions & 0 deletions src/main/java/io/appium/java_client/android/NetworkSpeed.java
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;
}
}
16 changes: 16 additions & 0 deletions src/main/java/io/appium/java_client/android/PowerACState.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down