Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 12 additions & 4 deletions src/main/java/io/appium/java_client/InteractsWithApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.appium.java_client.appmanagement.BaseOptions;
import io.appium.java_client.appmanagement.BaseRemoveApplicationOptions;
import io.appium.java_client.appmanagement.BaseTerminateApplicationOptions;
import org.openqa.selenium.UnsupportedCommandException;

import javax.annotation.Nullable;
import java.time.Duration;
Expand Down Expand Up @@ -76,15 +77,22 @@ default boolean isAppInstalled(String bundleId) {
}

/**
* Runs the current app as a background app for the time
* Runs the current app in the background for the time
* requested. This is a synchronous method, it blocks while the
* application is in background.
*
* @param duration The time to run App in background. Minimum time resolution is one millisecond.
* Passing zero or a negative value will switch to Home screen and return immediately.
* @param duration The time to run App in background. Minimum time resolution unit is one millisecond.
* Passing a negative value will switch to Home screen and return immediately.
*/
default void runAppInBackground(Duration duration) {
execute(RUN_APP_IN_BACKGROUND, ImmutableMap.of("seconds", duration.toMillis() / 1000.0));
try {
CommandExecutionHelper.executeScript(this, "mobile: backgroundApp", ImmutableMap.of(
"seconds", duration.toMillis() / 1000.0
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
execute(RUN_APP_IN_BACKGROUND, ImmutableMap.of("seconds", duration.toMillis() / 1000.0));
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class MobileCommand {
protected static final String PULL_FILE;
@Deprecated
protected static final String PULL_FOLDER;
@Deprecated
public static final String RUN_APP_IN_BACKGROUND;
@Deprecated
protected static final String PERFORM_TOUCH_ACTION;
Expand Down