Skip to content

Commit cf8eb85

Browse files
saikrishna321SrinivasanTarget
authored andcommitted
added get_current_package session (#657)
* added get_current_package session * fixed review * moved getCurrentPackage to StartActivity Interface
1 parent 37f5ed3 commit cf8eb85

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

src/main/java/io/appium/java_client/MobileCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class MobileCommand {
7676
protected static final String REPLACE_VALUE;
7777
protected static final String GET_SETTINGS;
7878
protected static final String SET_SETTINGS;
79+
protected static final String GET_CURRENT_PACKAGE;
7980

8081
public static final Map<String, AppiumCommandInfo> commandRepository;
8182

@@ -122,6 +123,7 @@ public class MobileCommand {
122123
REPLACE_VALUE = "replaceValue";
123124
GET_SETTINGS = "getSettings";
124125
SET_SETTINGS = "setSettings";
126+
GET_CURRENT_PACKAGE = "getCurrentPackage";
125127

126128
commandRepository = new HashMap<>();
127129
commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset"));
@@ -176,6 +178,7 @@ public class MobileCommand {
176178
postC("/session/:sessionId/appium/device/toggle_location_services"));
177179
commandRepository.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"));
178180
commandRepository. put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value"));
181+
commandRepository.put(GET_CURRENT_PACKAGE,getC("/session/:sessionId/appium/device/current_package"));
179182
}
180183

181184
/**

src/main/java/io/appium/java_client/android/AndroidDriver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,5 @@ public void openNotifications() {
180180
public void toggleLocationServices() {
181181
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
182182
}
183+
183184
}

src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public class AndroidMobileCommandHelper extends MobileCommand {
4646
CURRENT_ACTIVITY, ImmutableMap.<String, Object>of());
4747
}
4848

49+
/**
50+
* This method forms a {@link java.util.Map} of parameters for the
51+
* getting of the current package.
52+
*
53+
* @return a key-value pair. The key is the command name. The value is a
54+
* {@link java.util.Map} command arguments.
55+
*/
56+
public static Map.Entry<String, Map<String, ?>> currentPackageCommand() {
57+
return new AbstractMap.SimpleEntry<>(
58+
GET_CURRENT_PACKAGE, ImmutableMap.<String, Object>of());
59+
}
60+
4961
/**
5062
* This method forms a {@link java.util.Map} of parameters for the
5163
* ending of the test coverage.

src/main/java/io/appium/java_client/android/StartsActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.appium.java_client.android;
1818

1919
import static io.appium.java_client.android.AndroidMobileCommandHelper.currentActivityCommand;
20+
import static io.appium.java_client.android.AndroidMobileCommandHelper.currentPackageCommand;
2021
import static io.appium.java_client.android.AndroidMobileCommandHelper.startActivityCommand;
2122

2223
import io.appium.java_client.CommandExecutionHelper;
@@ -158,4 +159,13 @@ default void startActivity(String appPackage, String appActivity, String appWait
158159
default String currentActivity() {
159160
return CommandExecutionHelper.execute(this, currentActivityCommand());
160161
}
162+
163+
/**
164+
* Get the current package being run on the mobile device.
165+
*
166+
* @return a current package being run on the mobile device.
167+
*/
168+
default String getCurrentPackage() {
169+
return CommandExecutionHelper.execute(this, currentPackageCommand());
170+
}
161171
}

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,8 @@ public class AndroidDriverTest extends BaseAndroidTest {
183183

184184
}
185185

186+
@Test public void getCurrentPackageTest() {
187+
assertEquals("io.appium.android.apis",driver.getCurrentPackage());
188+
}
189+
186190
}

0 commit comments

Comments
 (0)