From 404b8fed3a142c476546c086be04fdb49ab7d338 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Wed, 26 Apr 2023 08:04:55 +0200 Subject: [PATCH] refactor: Change backgroundApp command to use the corresponding mobile extension --- .../io/appium/java_client/InteractsWithApps.java | 16 ++++++++++++---- .../io/appium/java_client/MobileCommand.java | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/appium/java_client/InteractsWithApps.java b/src/main/java/io/appium/java_client/InteractsWithApps.java index fedf957c8..0793cd79f 100644 --- a/src/main/java/io/appium/java_client/InteractsWithApps.java +++ b/src/main/java/io/appium/java_client/InteractsWithApps.java @@ -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; @@ -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)); + } } /** diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 8c2f4f350..5b2a6587d 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -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;