From 374f51f949e503036e29a529ab2eb50c48fcbf3e Mon Sep 17 00:00:00 2001 From: theluckystrike <51033404+theluckystrike@users.noreply.github.com> Date: Sat, 10 Oct 2026 12:28:47 +0700 Subject: [PATCH] feat: add the autoLaunch option to UiAutomator2Options and XCUITestOptions --- .../android/options/UiAutomator2Options.java | 2 + .../ios/options/XCUITestOptions.java | 2 + .../options/SupportsAutoLaunchOption.java | 67 +++++++++++++++++++ .../drivers/options/OptionsBuildingTest.java | 20 ++++++ 4 files changed, 91 insertions(+) create mode 100644 src/main/java/io/appium/java_client/remote/options/SupportsAutoLaunchOption.java diff --git a/src/main/java/io/appium/java_client/android/options/UiAutomator2Options.java b/src/main/java/io/appium/java_client/android/options/UiAutomator2Options.java index 9ed02775b..f7408cf70 100644 --- a/src/main/java/io/appium/java_client/android/options/UiAutomator2Options.java +++ b/src/main/java/io/appium/java_client/android/options/UiAutomator2Options.java @@ -90,6 +90,7 @@ import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.remote.options.BaseOptions; import io.appium.java_client.remote.options.SupportsAppOption; +import io.appium.java_client.remote.options.SupportsAutoLaunchOption; import io.appium.java_client.remote.options.SupportsAutoWebViewOption; import io.appium.java_client.remote.options.SupportsClearSystemFilesOption; import io.appium.java_client.remote.options.SupportsDeviceNameOption; @@ -141,6 +142,7 @@ public class UiAutomator2Options extends BaseOptions implem SupportsIntentFlagsOption, SupportsOptionalIntentArgumentsOption, SupportsAutoGrantPermissionsOption, + SupportsAutoLaunchOption, SupportsOtherAppsOption, SupportsUninstallOtherPackagesOption, SupportsAllowTestPackagesOption, diff --git a/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java b/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java index 42066db40..5dc2714ae 100644 --- a/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java +++ b/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java @@ -104,6 +104,7 @@ import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.remote.options.BaseOptions; import io.appium.java_client.remote.options.SupportsAppOption; +import io.appium.java_client.remote.options.SupportsAutoLaunchOption; import io.appium.java_client.remote.options.SupportsAutoWebViewOption; import io.appium.java_client.remote.options.SupportsClearSystemFilesOption; import io.appium.java_client.remote.options.SupportsDeviceNameOption; @@ -142,6 +143,7 @@ public class XCUITestOptions extends BaseOptions implements SupportsOtherAppsOption, SupportsAppPushTimeoutOption, SupportsAppInstallStrategyOption, + SupportsAutoLaunchOption, SupportsEnforceAppInstallOption, // WebDriverAgent options: https://github.com/appium/appium-xcuitest-driver#webdriveragent SupportsXcodeCertificateOptions, diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsAutoLaunchOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsAutoLaunchOption.java new file mode 100644 index 000000000..0109732ab --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsAutoLaunchOption.java @@ -0,0 +1,67 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +/** + * Provides getters and setters for the {@code autoLaunch} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsAutoLaunchOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code autoLaunch} capability. + */ + String AUTO_LAUNCH_OPTION = "autoLaunch"; + + /** + * Enables launching of the application under test automatically + * when a test starts. + * + * @return self instance for chaining. + */ + default T autoLaunch() { + return amend(AUTO_LAUNCH_OPTION, true); + } + + /** + * Whether to launch the application under test automatically + * when a test starts (true, the default value). + * + * @param value Whether to enable or disable automatic app launching. + * @return self instance for chaining. + */ + default T setAutoLaunch(boolean value) { + return amend(AUTO_LAUNCH_OPTION, value); + } + + /** + * Get whether to launch the application under test automatically + * when a test starts. + * + * @return True if the app should be launched automatically. + */ + default Optional doesAutoLaunch() { + return Optional.ofNullable(toSafeBoolean(getCapability(AUTO_LAUNCH_OPTION))); + } +} diff --git a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java index 4ab700ca3..f1a86dc80 100644 --- a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java +++ b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java @@ -93,6 +93,26 @@ public void canBuildUiAutomator2Options() throws MalformedURLException { assertTrue(options.doesSuppressKillServer().orElse(false)); } + @Test + public void canSetAutoLaunchOnUiAutomator2Options() { + UiAutomator2Options options = new UiAutomator2Options(); + assertFalse(options.doesAutoLaunch().isPresent()); + options.autoLaunch(); + assertTrue(options.doesAutoLaunch().orElse(false)); + options.setAutoLaunch(false); + assertFalse(options.doesAutoLaunch().orElse(true)); + } + + @Test + public void canSetAutoLaunchOnXcuiTestOptions() { + XCUITestOptions options = new XCUITestOptions(); + assertFalse(options.doesAutoLaunch().isPresent()); + options.setAutoLaunch(false); + assertFalse(options.doesAutoLaunch().orElse(true)); + options.autoLaunch(); + assertTrue(options.doesAutoLaunch().orElse(false)); + } + @Test public void canBuildEspressoOptions() { EspressoOptions options = new EspressoOptions();