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
3 changes: 3 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.appium.java_client.android;

import static io.appium.java_client.android.AndroidMobileCommandHelper.currentPackageCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.endTestCoverageCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.openNotificationsCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand;
Expand Down Expand Up @@ -180,4 +181,8 @@ public void openNotifications() {
public void toggleLocationServices() {
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
}

public String getCurrentPackage() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to move this method to the io.appium.java_client.android.StartsActivity interface and to make it default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

return CommandExecutionHelper.execute(this, currentPackageCommand());
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,8 @@ public class AndroidDriverTest extends BaseAndroidTest {

}

@Test public void getCurrentPackage() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename this to getCurrentPackageTest() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

assertEquals("io.appium.android.apis",driver.getCurrentPackage());
}

}