Skip to content

Commit

Permalink
added get_current_package session (appium#657)
Browse files Browse the repository at this point in the history
* added get_current_package session

* fixed review

* moved getCurrentPackage to StartActivity Interface
  • Loading branch information
saikrishna321 authored and SrinivasanTarget committed Sep 3, 2017
1 parent 18a0806 commit 67fbab3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Expand Up @@ -76,6 +76,7 @@ public class MobileCommand {
protected static final String REPLACE_VALUE;
protected static final String GET_SETTINGS;
protected static final String SET_SETTINGS;
protected static final String GET_CURRENT_PACKAGE;

public static final Map<String, AppiumCommandInfo> commandRepository;

Expand Down Expand Up @@ -122,6 +123,7 @@ public class MobileCommand {
REPLACE_VALUE = "replaceValue";
GET_SETTINGS = "getSettings";
SET_SETTINGS = "setSettings";
GET_CURRENT_PACKAGE = "getCurrentPackage";

commandRepository = new HashMap<>();
commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset"));
Expand Down Expand Up @@ -176,6 +178,7 @@ public class MobileCommand {
postC("/session/:sessionId/appium/device/toggle_location_services"));
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"));
}

/**
Expand Down
Expand Up @@ -172,4 +172,5 @@ public void openNotifications() {
public void toggleLocationServices() {
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
}

}
Expand Up @@ -46,6 +46,18 @@ public class AndroidMobileCommandHelper extends MobileCommand {
CURRENT_ACTIVITY, ImmutableMap.<String, Object>of());
}

/**
* This method forms a {@link java.util.Map} of parameters for the
* getting of the current package.
*
* @return a key-value pair. The key is the command name. The value is a
* {@link java.util.Map} command arguments.
*/
public static Map.Entry<String, Map<String, ?>> currentPackageCommand() {
return new AbstractMap.SimpleEntry<>(
GET_CURRENT_PACKAGE, ImmutableMap.<String, Object>of());
}

/**
* This method forms a {@link java.util.Map} of parameters for the
* ending of the test coverage.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/appium/java_client/android/StartsActivity.java
Expand Up @@ -17,6 +17,7 @@
package io.appium.java_client.android;

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;

import io.appium.java_client.CommandExecutionHelper;
Expand Down Expand Up @@ -56,4 +57,13 @@ default void startActivity(Activity activity) {
default String currentActivity() {
return CommandExecutionHelper.execute(this, currentActivityCommand());
}

/**
* Get the current package being run on the mobile device.
*
* @return a current package being run on the mobile device.
*/
default String getCurrentPackage() {
return CommandExecutionHelper.execute(this, currentPackageCommand());
}
}
Expand Up @@ -181,4 +181,8 @@ public class AndroidDriverTest extends BaseAndroidTest {

}

@Test public void getCurrentPackageTest() {
assertEquals("io.appium.android.apis",driver.getCurrentPackage());
}

}

0 comments on commit 67fbab3

Please sign in to comment.