diff --git a/src/main/java/io/appium/java_client/android/options/EspressoOptions.java b/src/main/java/io/appium/java_client/android/options/EspressoOptions.java index c4316915f..6d2b7f6e9 100644 --- a/src/main/java/io/appium/java_client/android/options/EspressoOptions.java +++ b/src/main/java/io/appium/java_client/android/options/EspressoOptions.java @@ -17,8 +17,10 @@ package io.appium.java_client.android.options; import io.appium.java_client.android.options.adb.SupportsAdbExecTimeoutOption; +import io.appium.java_client.android.options.adb.SupportsAdbListenAllNetworkOption; import io.appium.java_client.android.options.adb.SupportsAdbPortOption; import io.appium.java_client.android.options.adb.SupportsAllowDelayAdbOption; +import io.appium.java_client.android.options.adb.SupportsAllowOfflineDevicesOption; import io.appium.java_client.android.options.adb.SupportsBuildToolsVersionOption; import io.appium.java_client.android.options.adb.SupportsClearDeviceLogsOnStartOption; import io.appium.java_client.android.options.adb.SupportsIgnoreHiddenApiPolicyErrorOption; @@ -37,6 +39,7 @@ import io.appium.java_client.android.options.app.SupportsAppWaitDurationOption; import io.appium.java_client.android.options.app.SupportsAppWaitPackageOption; import io.appium.java_client.android.options.app.SupportsAutoGrantPermissionsOption; +import io.appium.java_client.android.options.app.SupportsDontStopAppOnResetOption; import io.appium.java_client.android.options.app.SupportsIntentOptionsOption; import io.appium.java_client.android.options.app.SupportsRemoteAppsCacheLimitOption; import io.appium.java_client.android.options.app.SupportsUninstallOtherPackagesOption; @@ -47,6 +50,7 @@ import io.appium.java_client.android.options.avd.SupportsAvdReadyTimeoutOption; import io.appium.java_client.android.options.avd.SupportsGpsEnabledOption; import io.appium.java_client.android.options.avd.SupportsNetworkSpeedOption; +import io.appium.java_client.android.options.context.SupportsAutoWebviewNameOption; import io.appium.java_client.android.options.context.SupportsAutoWebviewTimeoutOption; import io.appium.java_client.android.options.context.SupportsChromeLoggingPrefsOption; import io.appium.java_client.android.options.context.SupportsChromeOptionsOption; @@ -55,9 +59,12 @@ import io.appium.java_client.android.options.context.SupportsChromedriverDisableBuildCheckOption; import io.appium.java_client.android.options.context.SupportsChromedriverExecutableDirOption; import io.appium.java_client.android.options.context.SupportsChromedriverExecutableOption; +import io.appium.java_client.android.options.context.SupportsChromedriverForwardBiDiOption; +import io.appium.java_client.android.options.context.SupportsChromedriverGrantPermissionsOption; import io.appium.java_client.android.options.context.SupportsChromedriverPortOption; import io.appium.java_client.android.options.context.SupportsChromedriverPortsOption; import io.appium.java_client.android.options.context.SupportsChromedriverUseSystemExecutableOption; +import io.appium.java_client.android.options.context.SupportsEnableWebviewDetailsCollectionOption; import io.appium.java_client.android.options.context.SupportsEnsureWebviewsHavePagesOption; import io.appium.java_client.android.options.context.SupportsExtractChromeAndroidPackageFromContextNameOption; import io.appium.java_client.android.options.context.SupportsNativeWebScreenshotOption; @@ -66,6 +73,7 @@ import io.appium.java_client.android.options.context.SupportsWebviewDevtoolsPortOption; import io.appium.java_client.android.options.localization.SupportsAppLocaleOption; import io.appium.java_client.android.options.localization.SupportsLocaleScriptOption; +import io.appium.java_client.android.options.localization.SupportsTimeZoneOption; import io.appium.java_client.android.options.locking.SupportsSkipUnlockOption; import io.appium.java_client.android.options.locking.SupportsUnlockKeyOption; import io.appium.java_client.android.options.locking.SupportsUnlockStrategyOption; @@ -79,6 +87,7 @@ import io.appium.java_client.android.options.server.SupportsForceEspressoRebuildOption; import io.appium.java_client.android.options.server.SupportsShowGradleLogOption; import io.appium.java_client.android.options.server.SupportsSkipServerInstallationOption; +import io.appium.java_client.android.options.server.SupportsSkipSettingsAppReinstallOption; import io.appium.java_client.android.options.server.SupportsSystemPortOption; import io.appium.java_client.android.options.signing.SupportsKeystoreOptions; import io.appium.java_client.android.options.signing.SupportsNoSignOption; @@ -115,6 +124,7 @@ public class EspressoOptions extends BaseOptions implements // Driver/Server options: https://appium.github.io/appium-espresso-driver/latest/reference/capabilities/#espresso-server SupportsSystemPortOption, SupportsSkipServerInstallationOption, + SupportsSkipSettingsAppReinstallOption, SupportsEspressoServerLaunchTimeoutOption, SupportsForceEspressoRebuildOption, SupportsShowGradleLogOption, @@ -131,6 +141,7 @@ public class EspressoOptions extends BaseOptions implements SupportsIntentOptionsOption, SupportsActivityOptionsOption, SupportsAutoGrantPermissionsOption, + SupportsDontStopAppOnResetOption, SupportsOtherAppsOption, SupportsUninstallOtherPackagesOption, SupportsAllowTestPackagesOption, @@ -140,6 +151,7 @@ public class EspressoOptions extends BaseOptions implements SupportsLocaleScriptOption, SupportsLanguageOption, SupportsLocaleOption, + SupportsTimeZoneOption, SupportsAppLocaleOption, // ADB options: https://appium.github.io/appium-espresso-driver/latest/reference/capabilities/#adb SupportsAdbPortOption, @@ -148,7 +160,9 @@ public class EspressoOptions extends BaseOptions implements SupportsClearDeviceLogsOnStartOption, SupportsBuildToolsVersionOption, SupportsSkipLogcatCaptureOption, + SupportsAllowOfflineDevicesOption, SupportsSuppressKillServerOption, + SupportsAdbListenAllNetworkOption, SupportsIgnoreHiddenApiPolicyErrorOption, SupportsMockLocationAppOption, SupportsLogcatFormatOption, @@ -177,8 +191,10 @@ public class EspressoOptions extends BaseOptions implements SupportsMjpegScreenshotUrlOption, // Web Context options: https://appium.github.io/appium-espresso-driver/latest/reference/capabilities/#web-context SupportsAutoWebViewOption, + SupportsAutoWebviewNameOption, SupportsWebviewDevtoolsPortOption, SupportsEnsureWebviewsHavePagesOption, + SupportsEnableWebviewDetailsCollectionOption, SupportsChromedriverPortOption, SupportsChromedriverPortsOption, SupportsChromedriverArgsOption, @@ -187,6 +203,8 @@ public class EspressoOptions extends BaseOptions implements SupportsChromedriverChromeMappingFileOption, SupportsChromedriverUseSystemExecutableOption, SupportsChromedriverDisableBuildCheckOption, + SupportsChromedriverForwardBiDiOption, + SupportsChromedriverGrantPermissionsOption, SupportsAutoWebviewTimeoutOption, SupportsRecreateChromeDriverSessionsOption, SupportsNativeWebScreenshotOption, 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 352760270..fe3e9ac54 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 @@ -17,8 +17,10 @@ package io.appium.java_client.android.options; import io.appium.java_client.android.options.adb.SupportsAdbExecTimeoutOption; +import io.appium.java_client.android.options.adb.SupportsAdbListenAllNetworkOption; import io.appium.java_client.android.options.adb.SupportsAdbPortOption; import io.appium.java_client.android.options.adb.SupportsAllowDelayAdbOption; +import io.appium.java_client.android.options.adb.SupportsAllowOfflineDevicesOption; import io.appium.java_client.android.options.adb.SupportsBuildToolsVersionOption; import io.appium.java_client.android.options.adb.SupportsClearDeviceLogsOnStartOption; import io.appium.java_client.android.options.adb.SupportsIgnoreHiddenApiPolicyErrorOption; @@ -37,11 +39,14 @@ import io.appium.java_client.android.options.app.SupportsAppWaitForLaunchOption; import io.appium.java_client.android.options.app.SupportsAppWaitPackageOption; import io.appium.java_client.android.options.app.SupportsAutoGrantPermissionsOption; +import io.appium.java_client.android.options.app.SupportsDontStopAppOnResetOption; +import io.appium.java_client.android.options.app.SupportsForceAppLaunchOption; import io.appium.java_client.android.options.app.SupportsIntentActionOption; import io.appium.java_client.android.options.app.SupportsIntentCategoryOption; import io.appium.java_client.android.options.app.SupportsIntentFlagsOption; import io.appium.java_client.android.options.app.SupportsOptionalIntentArgumentsOption; import io.appium.java_client.android.options.app.SupportsRemoteAppsCacheLimitOption; +import io.appium.java_client.android.options.app.SupportsShouldTerminateAppOption; import io.appium.java_client.android.options.app.SupportsUninstallOtherPackagesOption; import io.appium.java_client.android.options.avd.SupportsAvdArgsOption; import io.appium.java_client.android.options.avd.SupportsAvdEnvOption; @@ -50,6 +55,7 @@ import io.appium.java_client.android.options.avd.SupportsAvdReadyTimeoutOption; import io.appium.java_client.android.options.avd.SupportsGpsEnabledOption; import io.appium.java_client.android.options.avd.SupportsNetworkSpeedOption; +import io.appium.java_client.android.options.context.SupportsAutoWebviewNameOption; import io.appium.java_client.android.options.context.SupportsAutoWebviewTimeoutOption; import io.appium.java_client.android.options.context.SupportsChromeLoggingPrefsOption; import io.appium.java_client.android.options.context.SupportsChromeOptionsOption; @@ -58,9 +64,12 @@ import io.appium.java_client.android.options.context.SupportsChromedriverDisableBuildCheckOption; import io.appium.java_client.android.options.context.SupportsChromedriverExecutableDirOption; import io.appium.java_client.android.options.context.SupportsChromedriverExecutableOption; +import io.appium.java_client.android.options.context.SupportsChromedriverForwardBiDiOption; +import io.appium.java_client.android.options.context.SupportsChromedriverGrantPermissionsOption; import io.appium.java_client.android.options.context.SupportsChromedriverPortOption; import io.appium.java_client.android.options.context.SupportsChromedriverPortsOption; import io.appium.java_client.android.options.context.SupportsChromedriverUseSystemExecutableOption; +import io.appium.java_client.android.options.context.SupportsEnableWebviewDetailsCollectionOption; import io.appium.java_client.android.options.context.SupportsEnsureWebviewsHavePagesOption; import io.appium.java_client.android.options.context.SupportsExtractChromeAndroidPackageFromContextNameOption; import io.appium.java_client.android.options.context.SupportsNativeWebScreenshotOption; @@ -68,6 +77,7 @@ import io.appium.java_client.android.options.context.SupportsShowChromedriverLogOption; import io.appium.java_client.android.options.context.SupportsWebviewDevtoolsPortOption; import io.appium.java_client.android.options.localization.SupportsLocaleScriptOption; +import io.appium.java_client.android.options.localization.SupportsTimeZoneOption; import io.appium.java_client.android.options.locking.SupportsSkipUnlockOption; import io.appium.java_client.android.options.locking.SupportsUnlockKeyOption; import io.appium.java_client.android.options.locking.SupportsUnlockStrategyOption; @@ -76,10 +86,12 @@ import io.appium.java_client.android.options.mjpeg.SupportsMjpegScreenshotUrlOption; import io.appium.java_client.android.options.mjpeg.SupportsMjpegServerPortOption; import io.appium.java_client.android.options.other.SupportsDisableSuppressAccessibilityServiceOption; +import io.appium.java_client.android.options.other.SupportsEnableAccessibilityEventsServiceOption; import io.appium.java_client.android.options.other.SupportsUserProfileOption; import io.appium.java_client.android.options.server.SupportsDisableWindowAnimationOption; import io.appium.java_client.android.options.server.SupportsSkipDeviceInitializationOption; import io.appium.java_client.android.options.server.SupportsSkipServerInstallationOption; +import io.appium.java_client.android.options.server.SupportsSkipSettingsAppReinstallOption; import io.appium.java_client.android.options.server.SupportsSystemPortOption; import io.appium.java_client.android.options.server.SupportsUiautomator2ServerInstallTimeoutOption; import io.appium.java_client.android.options.server.SupportsUiautomator2ServerLaunchTimeoutOption; @@ -118,16 +130,19 @@ public class UiAutomator2Options extends BaseOptions implem SupportsDeviceNameOption, SupportsUdidOption, SupportsSkipDeviceInitializationOption, + SupportsSkipSettingsAppReinstallOption, SupportsSkipLogcatCaptureOption, SupportsClearDeviceLogsOnStartOption, SupportsLogcatFormatOption, SupportsLogcatFilterSpecsOption, SupportsIgnoreHiddenApiPolicyErrorOption, SupportsDisableSuppressAccessibilityServiceOption, + SupportsEnableAccessibilityEventsServiceOption, SupportsDisableWindowAnimationOption, SupportsLanguageOption, SupportsLocaleOption, SupportsLocaleScriptOption, + SupportsTimeZoneOption, SupportsOrientationOption, SupportsGpsEnabledOption, SupportsMockLocationAppOption, @@ -150,7 +165,9 @@ public class UiAutomator2Options extends BaseOptions implem SupportsRemoteAdbHostOption, SupportsAdbExecTimeoutOption, SupportsBuildToolsVersionOption, + SupportsAllowOfflineDevicesOption, SupportsSuppressKillServerOption, + SupportsAdbListenAllNetworkOption, // UIA2 Server options: https://appium.github.io/appium-uiautomator2-driver/latest/reference/capabilities/#uiautomator2-server SupportsSystemPortOption, SupportsUiautomator2ServerInstallTimeoutOption, @@ -173,6 +190,9 @@ public class UiAutomator2Options extends BaseOptions implem SupportsOptionalIntentArgumentsOption, SupportsAndroidInstallTimeoutOption, SupportsEnforceAppInstallOption, + SupportsDontStopAppOnResetOption, + SupportsForceAppLaunchOption, + SupportsShouldTerminateAppOption, SupportsAutoGrantPermissionsOption, SupportsUserProfileOption, SupportsOtherAppsOption, @@ -184,9 +204,11 @@ public class UiAutomator2Options extends BaseOptions implem SupportsNoSignOption, // Web Context options: https://appium.github.io/appium-uiautomator2-driver/latest/reference/capabilities/#web-context SupportsAutoWebViewOption, + SupportsAutoWebviewNameOption, SupportsAutoWebviewTimeoutOption, SupportsWebviewDevtoolsPortOption, SupportsEnsureWebviewsHavePagesOption, + SupportsEnableWebviewDetailsCollectionOption, SupportsChromeOptionsOption, SupportsChromeLoggingPrefsOption, SupportsChromedriverPortOption, @@ -197,6 +219,8 @@ public class UiAutomator2Options extends BaseOptions implem SupportsChromedriverChromeMappingFileOption, SupportsChromedriverUseSystemExecutableOption, SupportsChromedriverDisableBuildCheckOption, + SupportsChromedriverForwardBiDiOption, + SupportsChromedriverGrantPermissionsOption, SupportsRecreateChromeDriverSessionsOption, SupportsNativeWebScreenshotOption, SupportsExtractChromeAndroidPackageFromContextNameOption, diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbListenAllNetworkOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbListenAllNetworkOption.java new file mode 100644 index 000000000..71c97dcf3 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbListenAllNetworkOption.java @@ -0,0 +1,66 @@ +/* + * 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.android.options.adb; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 adbListenAllNetwork} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsAdbListenAllNetworkOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code adbListenAllNetwork} capability. + */ + String ADB_LISTEN_ALL_NETWORK_OPTION = "adbListenAllNetwork"; + + /** + * Enables listening on all network interfaces for ADB instead of only localhost. + * + * @return self instance for chaining. + */ + default T adbListenAllNetwork() { + return amend(ADB_LISTEN_ALL_NETWORK_OPTION, true); + } + + /** + * Whether to listen on all network interfaces for ADB rather than only localhost. + * + * @param value True to listen on all network interfaces. + * @return self instance for chaining. + */ + default T setAdbListenAllNetwork(boolean value) { + return amend(ADB_LISTEN_ALL_NETWORK_OPTION, value); + } + + /** + * Get whether ADB listens on all network interfaces. + * + * @return True or false. + */ + default Optional doesAdbListenAllNetwork() { + return Optional.ofNullable(toSafeBoolean(getCapability(ADB_LISTEN_ALL_NETWORK_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsAllowOfflineDevicesOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsAllowOfflineDevicesOption.java new file mode 100644 index 000000000..442e423dd --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsAllowOfflineDevicesOption.java @@ -0,0 +1,66 @@ +/* + * 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.android.options.adb; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 allowOfflineDevices} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsAllowOfflineDevicesOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code allowOfflineDevices} capability. + */ + String ALLOW_OFFLINE_DEVICES_OPTION = "allowOfflineDevices"; + + /** + * Includes offline devices in the list of devices returned by ADB. + * + * @return self instance for chaining. + */ + default T allowOfflineDevices() { + return amend(ALLOW_OFFLINE_DEVICES_OPTION, true); + } + + /** + * Whether to include offline devices in the list of devices returned by ADB. + * + * @param value True to include offline devices. + * @return self instance for chaining. + */ + default T setAllowOfflineDevices(boolean value) { + return amend(ALLOW_OFFLINE_DEVICES_OPTION, value); + } + + /** + * Get whether offline devices are included in the ADB device list. + * + * @return True or false. + */ + default Optional doesAllowOfflineDevices() { + return Optional.ofNullable(toSafeBoolean(getCapability(ALLOW_OFFLINE_DEVICES_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsDontStopAppOnResetOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsDontStopAppOnResetOption.java new file mode 100644 index 000000000..ae175dda5 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsDontStopAppOnResetOption.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.android.options.app; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 dontStopAppOnReset} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsDontStopAppOnResetOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code dontStopAppOnReset} capability. + */ + String DONT_STOP_APP_ON_RESET_OPTION = "dontStopAppOnReset"; + + /** + * Skips stopping the app under test during session start and deletion. + * + * @return self instance for chaining. + */ + default T dontStopAppOnReset() { + return amend(DONT_STOP_APP_ON_RESET_OPTION, true); + } + + /** + * Whether to skip terminating the app under test upon session start and deletion + * when the app is already running. + * + * @param value True to avoid stopping the app on reset. + * @return self instance for chaining. + */ + default T setDontStopAppOnReset(boolean value) { + return amend(DONT_STOP_APP_ON_RESET_OPTION, value); + } + + /** + * Get whether terminating the app under test on reset is skipped. + * + * @return True or false. + */ + default Optional doesDontStopAppOnReset() { + return Optional.ofNullable(toSafeBoolean(getCapability(DONT_STOP_APP_ON_RESET_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsForceAppLaunchOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsForceAppLaunchOption.java new file mode 100644 index 000000000..64136a25d --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsForceAppLaunchOption.java @@ -0,0 +1,66 @@ +/* + * 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.android.options.app; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 forceAppLaunch} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsForceAppLaunchOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code forceAppLaunch} capability. + */ + String FORCE_APP_LAUNCH_OPTION = "forceAppLaunch"; + + /** + * Relaunches the app upon session startup even when {@code noReset} is enabled. + * + * @return self instance for chaining. + */ + default T forceAppLaunch() { + return amend(FORCE_APP_LAUNCH_OPTION, true); + } + + /** + * Whether to relaunch the app upon session startup even if {@code noReset} is set. + * + * @param value True to enforce app relaunch on session startup. + * @return self instance for chaining. + */ + default T setForceAppLaunch(boolean value) { + return amend(FORCE_APP_LAUNCH_OPTION, value); + } + + /** + * Get whether app relaunch on session startup is enforced. + * + * @return True or false. + */ + default Optional doesForceAppLaunch() { + return Optional.ofNullable(toSafeBoolean(getCapability(FORCE_APP_LAUNCH_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsShouldTerminateAppOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsShouldTerminateAppOption.java new file mode 100644 index 000000000..b76664011 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsShouldTerminateAppOption.java @@ -0,0 +1,66 @@ +/* + * 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.android.options.app; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 shouldTerminateApp} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsShouldTerminateAppOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code shouldTerminateApp} capability. + */ + String SHOULD_TERMINATE_APP_OPTION = "shouldTerminateApp"; + + /** + * Terminates the app upon session deletion even when {@code noReset} is enabled. + * + * @return self instance for chaining. + */ + default T shouldTerminateApp() { + return amend(SHOULD_TERMINATE_APP_OPTION, true); + } + + /** + * Whether to stop the app upon session deletion even if {@code noReset} is set. + * + * @param value True to enforce app termination on session deletion. + * @return self instance for chaining. + */ + default T setShouldTerminateApp(boolean value) { + return amend(SHOULD_TERMINATE_APP_OPTION, value); + } + + /** + * Get whether app termination on session deletion is enforced. + * + * @return True or false. + */ + default Optional doesTerminateApp() { + return Optional.ofNullable(toSafeBoolean(getCapability(SHOULD_TERMINATE_APP_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/context/SupportsAutoWebviewNameOption.java b/src/main/java/io/appium/java_client/android/options/context/SupportsAutoWebviewNameOption.java new file mode 100644 index 000000000..dd8995c1b --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/context/SupportsAutoWebviewNameOption.java @@ -0,0 +1,59 @@ +/* + * 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.android.options.context; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +/** + * Provides getters and setters for the {@code autoWebviewName} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsAutoWebviewNameOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code autoWebviewName} capability. + */ + String AUTO_WEBVIEW_NAME_OPTION = "autoWebviewName"; + + /** + * Sets a custom name to replace the application package part in the + * {@code WEBVIEW_} context name (for example {@code com.example.app}) + * when {@code autoWebview} is enabled. The driver prepends {@code WEBVIEW_} + * automatically. + * + * @param name Custom name replacing the application package part of the context name. + * @return self instance for chaining. + */ + default T setAutoWebviewName(String name) { + return amend(AUTO_WEBVIEW_NAME_OPTION, name); + } + + /** + * Get the custom name replacing the application package part of the + * {@code WEBVIEW_} context name for {@code autoWebview}. + * + * @return Custom package part of the webview context name. + */ + default Optional getAutoWebviewName() { + return Optional.ofNullable((String) getCapability(AUTO_WEBVIEW_NAME_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/context/SupportsChromedriverForwardBiDiOption.java b/src/main/java/io/appium/java_client/android/options/context/SupportsChromedriverForwardBiDiOption.java new file mode 100644 index 000000000..89a8ea33b --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/context/SupportsChromedriverForwardBiDiOption.java @@ -0,0 +1,74 @@ +/* + * 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.android.options.context; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 chromedriverForwardBiDi} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsChromedriverForwardBiDiOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code chromedriverForwardBiDi} capability. + */ + String CHROMEDRIVER_FORWARD_BIDI_OPTION = "chromedriverForwardBiDi"; + + /** + * Enables forwarding the ChromeDriver BiDi WebSocket to the driver WebSocket + * when switching to a webview context. Requires BiDi to be enabled + * ({@code webSocketUrl} set to {@code true}, e.g. via {@code enableBiDi()}) + * to take effect. Supported since {@code appium-android-driver} 6.1.0. + * + * @return self instance for chaining. + */ + default T chromedriverForwardBiDi() { + return amend(CHROMEDRIVER_FORWARD_BIDI_OPTION, true); + } + + /** + * Whether to forward the ChromeDriver BiDi WebSocket to the driver WebSocket + * when switching to a webview context. Requires BiDi to be enabled + * ({@code webSocketUrl} set to {@code true}, e.g. via {@code enableBiDi()}) + * to take effect; calling only this setter without enabling BiDi produces no + * forwarding and no error. {@code false} by default. Supported since + * {@code appium-android-driver} 6.1.0. + * + * @param value True to enable ChromeDriver BiDi forwarding. + * @return self instance for chaining. + */ + default T setChromedriverForwardBiDi(boolean value) { + return amend(CHROMEDRIVER_FORWARD_BIDI_OPTION, value); + } + + /** + * Get whether ChromeDriver BiDi WebSocket forwarding is enabled. + * + * @return True or false. + */ + default Optional doesChromedriverForwardBiDi() { + return Optional.ofNullable(toSafeBoolean(getCapability(CHROMEDRIVER_FORWARD_BIDI_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/context/SupportsChromedriverGrantPermissionsOption.java b/src/main/java/io/appium/java_client/android/options/context/SupportsChromedriverGrantPermissionsOption.java new file mode 100644 index 000000000..4192e2b1f --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/context/SupportsChromedriverGrantPermissionsOption.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.android.options.context; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 chromedriverGrantPermissions} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsChromedriverGrantPermissionsOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code chromedriverGrantPermissions} capability. + */ + String CHROMEDRIVER_GRANT_PERMISSIONS_OPTION = "chromedriverGrantPermissions"; + + /** + * Automatically grants requested runtime permissions for Chrome or the webview package. + * + * @return self instance for chaining. + */ + default T chromedriverGrantPermissions() { + return amend(CHROMEDRIVER_GRANT_PERMISSIONS_OPTION, true); + } + + /** + * Whether to automatically grant requested runtime permissions for the Chrome + * or webview package. + * + * @param value True to auto-grant Chrome or webview runtime permissions. + * @return self instance for chaining. + */ + default T setChromedriverGrantPermissions(boolean value) { + return amend(CHROMEDRIVER_GRANT_PERMISSIONS_OPTION, value); + } + + /** + * Get whether runtime permissions are granted automatically for Chrome or the webview package. + * + * @return True or false. + */ + default Optional doesChromedriverGrantPermissions() { + return Optional.ofNullable(toSafeBoolean(getCapability(CHROMEDRIVER_GRANT_PERMISSIONS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/context/SupportsEnableWebviewDetailsCollectionOption.java b/src/main/java/io/appium/java_client/android/options/context/SupportsEnableWebviewDetailsCollectionOption.java new file mode 100644 index 000000000..1253f3260 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/context/SupportsEnableWebviewDetailsCollectionOption.java @@ -0,0 +1,70 @@ +/* + * 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.android.options.context; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 enableWebviewDetailsCollection} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsEnableWebviewDetailsCollectionOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code enableWebviewDetailsCollection} capability. + */ + String ENABLE_WEBVIEW_DETAILS_COLLECTION_OPTION = "enableWebviewDetailsCollection"; + + /** + * Disables retrieving extended webview metadata via DevTools. + * Extended webview details collection is {@code true} by default in the driver. + * + * @return self instance for chaining. + */ + default T disableWebviewDetailsCollection() { + return amend(ENABLE_WEBVIEW_DETAILS_COLLECTION_OPTION, false); + } + + /** + * Whether to retrieve extended webview information via DevTools to improve + * detection of the matching ChromeDriver version. {@code true} by default. + * + * @param value False to disable extended webview details collection, true to enable it. + * @return self instance for chaining. + */ + default T setEnableWebviewDetailsCollection(boolean value) { + return amend(ENABLE_WEBVIEW_DETAILS_COLLECTION_OPTION, value); + } + + /** + * Get whether extended webview details collection is enabled. + * + * @return True or false. + */ + default Optional doesEnableWebviewDetailsCollection() { + return Optional.ofNullable( + toSafeBoolean(getCapability(ENABLE_WEBVIEW_DETAILS_COLLECTION_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/localization/SupportsTimeZoneOption.java b/src/main/java/io/appium/java_client/android/options/localization/SupportsTimeZoneOption.java new file mode 100644 index 000000000..ce1b560b8 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/localization/SupportsTimeZoneOption.java @@ -0,0 +1,55 @@ +/* + * 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.android.options.localization; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +/** + * Provides getters and setters for the {@code timeZone} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsTimeZoneOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code timeZone} capability. + */ + String TIME_ZONE_OPTION = "timeZone"; + + /** + * Sets the time zone identifier used to override the device time zone. + * + * @param timeZone Valid TZ database identifier, for example {@code America/New_York}. + * @return self instance for chaining. + */ + default T setTimeZone(String timeZone) { + return amend(TIME_ZONE_OPTION, timeZone); + } + + /** + * Get the time zone identifier configured for the device. + * + * @return Time zone identifier. + */ + default Optional getTimeZone() { + return Optional.ofNullable((String) getCapability(TIME_ZONE_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/other/SupportsEnableAccessibilityEventsServiceOption.java b/src/main/java/io/appium/java_client/android/options/other/SupportsEnableAccessibilityEventsServiceOption.java new file mode 100644 index 000000000..c8a2964c4 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/other/SupportsEnableAccessibilityEventsServiceOption.java @@ -0,0 +1,75 @@ +/* + * 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.android.options.other; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 enableAccessibilityEventsService} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsEnableAccessibilityEventsServiceOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code enableAccessibilityEventsService} capability. + */ + String ENABLE_ACCESSIBILITY_EVENTS_SERVICE_OPTION = "enableAccessibilityEventsService"; + + /** + * Enables the Appium Settings accessibility events service for the session. + * Enabling this also stops suppressing accessibility services unless + * {@code disableSuppressAccessibilityService} is explicitly set to {@code false}. + * Supported since {@code appium-uiautomator2-driver} 9.1.0. + * + * @return self instance for chaining. + */ + default T enableAccessibilityEventsService() { + return amend(ENABLE_ACCESSIBILITY_EVENTS_SERVICE_OPTION, true); + } + + /** + * Whether to enable the Appium Settings no-op accessibility service for the + * duration of the session so Chrome emits accessibility events for web content. + * Enabling this also stops suppressing accessibility services unless + * {@code disableSuppressAccessibilityService} is explicitly set to {@code false}. + * {@code false} by default. Supported since {@code appium-uiautomator2-driver} 9.1.0. + * + * @param value True to enable the accessibility events service. + * @return self instance for chaining. + */ + default T setEnableAccessibilityEventsService(boolean value) { + return amend(ENABLE_ACCESSIBILITY_EVENTS_SERVICE_OPTION, value); + } + + /** + * Get whether the accessibility events service is enabled. + * + * @return True or false. + */ + default Optional doesEnableAccessibilityEventsService() { + return Optional.ofNullable( + toSafeBoolean(getCapability(ENABLE_ACCESSIBILITY_EVENTS_SERVICE_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsSkipSettingsAppReinstallOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsSkipSettingsAppReinstallOption.java new file mode 100644 index 000000000..46ac4be6c --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsSkipSettingsAppReinstallOption.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.android.options.server; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +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 skipSettingsAppReinstall} capability. + * + * @param options type, used for chaining. + */ +public interface SupportsSkipSettingsAppReinstallOption> extends + Capabilities, CanSetCapability { + /** + * Name of the {@code skipSettingsAppReinstall} capability. + */ + String SKIP_SETTINGS_APP_REINSTALL_OPTION = "skipSettingsAppReinstall"; + + /** + * Skips reinstalling the Appium Settings helper application on session start. + * + * @return self instance for chaining. + */ + default T skipSettingsAppReinstall() { + return amend(SKIP_SETTINGS_APP_REINSTALL_OPTION, true); + } + + /** + * Whether to skip installing or reinstalling the Appium Settings helper application + * upon session startup. + * + * @param value True to skip Appium Settings reinstallation. + * @return self instance for chaining. + */ + default T setSkipSettingsAppReinstall(boolean value) { + return amend(SKIP_SETTINGS_APP_REINSTALL_OPTION, value); + } + + /** + * Get whether reinstalling the Appium Settings helper application is skipped. + * + * @return True or false. + */ + default Optional doesSkipSettingsAppReinstall() { + return Optional.ofNullable(toSafeBoolean(getCapability(SKIP_SETTINGS_APP_REINSTALL_OPTION))); + } +} diff --git a/src/test/java/io/appium/java_client/drivers/options/AndroidOptionsParityTest.java b/src/test/java/io/appium/java_client/drivers/options/AndroidOptionsParityTest.java new file mode 100644 index 000000000..b28c2a0c3 --- /dev/null +++ b/src/test/java/io/appium/java_client/drivers/options/AndroidOptionsParityTest.java @@ -0,0 +1,284 @@ +/* + * 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.drivers.options; + +import io.appium.java_client.android.options.EspressoOptions; +import io.appium.java_client.android.options.UiAutomator2Options; +import io.appium.java_client.android.options.adb.SupportsAdbListenAllNetworkOption; +import io.appium.java_client.android.options.adb.SupportsAllowOfflineDevicesOption; +import io.appium.java_client.android.options.app.SupportsDontStopAppOnResetOption; +import io.appium.java_client.android.options.app.SupportsForceAppLaunchOption; +import io.appium.java_client.android.options.app.SupportsShouldTerminateAppOption; +import io.appium.java_client.android.options.context.SupportsAutoWebviewNameOption; +import io.appium.java_client.android.options.context.SupportsChromedriverForwardBiDiOption; +import io.appium.java_client.android.options.context.SupportsChromedriverGrantPermissionsOption; +import io.appium.java_client.android.options.context.SupportsEnableWebviewDetailsCollectionOption; +import io.appium.java_client.android.options.localization.SupportsTimeZoneOption; +import io.appium.java_client.android.options.other.SupportsEnableAccessibilityEventsServiceOption; +import io.appium.java_client.android.options.server.SupportsSkipSettingsAppReinstallOption; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.ImmutableCapabilities; + +import java.util.Map; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class AndroidOptionsParityTest { + + @Test + void uiAutomator2NewOptionsDefaultToEmpty() { + var options = new UiAutomator2Options(); + assertEquals(Optional.empty(), options.doesAdbListenAllNetwork()); + assertEquals(Optional.empty(), options.doesAllowOfflineDevices()); + assertEquals(Optional.empty(), options.doesDontStopAppOnReset()); + assertEquals(Optional.empty(), options.doesForceAppLaunch()); + assertEquals(Optional.empty(), options.doesTerminateApp()); + assertEquals(Optional.empty(), options.getAutoWebviewName()); + assertEquals(Optional.empty(), options.doesChromedriverForwardBiDi()); + assertEquals(Optional.empty(), options.doesChromedriverGrantPermissions()); + assertEquals(Optional.empty(), options.doesEnableWebviewDetailsCollection()); + assertEquals(Optional.empty(), options.getTimeZone()); + assertEquals(Optional.empty(), options.doesEnableAccessibilityEventsService()); + assertEquals(Optional.empty(), options.doesSkipSettingsAppReinstall()); + } + + @Test + void espressoNewOptionsDefaultToEmpty() { + var options = new EspressoOptions(); + assertEquals(Optional.empty(), options.doesAdbListenAllNetwork()); + assertEquals(Optional.empty(), options.doesAllowOfflineDevices()); + assertEquals(Optional.empty(), options.doesDontStopAppOnReset()); + assertEquals(Optional.empty(), options.getAutoWebviewName()); + assertEquals(Optional.empty(), options.doesChromedriverForwardBiDi()); + assertEquals(Optional.empty(), options.doesChromedriverGrantPermissions()); + assertEquals(Optional.empty(), options.doesEnableWebviewDetailsCollection()); + assertEquals(Optional.empty(), options.getTimeZone()); + assertEquals(Optional.empty(), options.doesSkipSettingsAppReinstall()); + } + + @Test + void uiAutomator2ChainedMethodsPopulateCapabilities() { + var options = new UiAutomator2Options() + .enableBiDi() + .adbListenAllNetwork() + .allowOfflineDevices() + .dontStopAppOnReset() + .forceAppLaunch() + .shouldTerminateApp() + .setAutoWebviewName("com.example.sample") + .chromedriverForwardBiDi() + .chromedriverGrantPermissions() + .disableWebviewDetailsCollection() + .setTimeZone("America/New_York") + .enableAccessibilityEventsService() + .skipSettingsAppReinstall(); + + assertEquals(Optional.of(true), options.getWebSocketUrl()); + assertEquals(Optional.of(true), options.doesAdbListenAllNetwork()); + assertEquals(Optional.of(true), options.doesAllowOfflineDevices()); + assertEquals(Optional.of(true), options.doesDontStopAppOnReset()); + assertEquals(Optional.of(true), options.doesForceAppLaunch()); + assertEquals(Optional.of(true), options.doesTerminateApp()); + assertEquals(Optional.of("com.example.sample"), options.getAutoWebviewName()); + assertEquals(Optional.of(true), options.doesChromedriverForwardBiDi()); + assertEquals(Optional.of(true), options.doesChromedriverGrantPermissions()); + assertEquals(Optional.of(false), options.doesEnableWebviewDetailsCollection()); + assertEquals(Optional.of("America/New_York"), options.getTimeZone()); + assertEquals(Optional.of(true), options.doesEnableAccessibilityEventsService()); + assertEquals(Optional.of(true), options.doesSkipSettingsAppReinstall()); + + Map capMap = options.asMap(); + assertEquals(true, capMap.get("appium:" + SupportsAdbListenAllNetworkOption.ADB_LISTEN_ALL_NETWORK_OPTION)); + assertEquals(true, capMap.get("appium:" + SupportsAllowOfflineDevicesOption.ALLOW_OFFLINE_DEVICES_OPTION)); + assertEquals(true, capMap.get("appium:" + SupportsDontStopAppOnResetOption.DONT_STOP_APP_ON_RESET_OPTION)); + assertEquals(true, capMap.get("appium:" + SupportsForceAppLaunchOption.FORCE_APP_LAUNCH_OPTION)); + assertEquals(true, capMap.get("appium:" + SupportsShouldTerminateAppOption.SHOULD_TERMINATE_APP_OPTION)); + assertEquals( + "com.example.sample", + capMap.get("appium:" + SupportsAutoWebviewNameOption.AUTO_WEBVIEW_NAME_OPTION) + ); + assertEquals( + true, + capMap.get("appium:" + SupportsChromedriverForwardBiDiOption.CHROMEDRIVER_FORWARD_BIDI_OPTION) + ); + assertEquals( + true, + capMap.get("appium:" + SupportsChromedriverGrantPermissionsOption.CHROMEDRIVER_GRANT_PERMISSIONS_OPTION) + ); + assertEquals( + false, + capMap.get( + "appium:" + + SupportsEnableWebviewDetailsCollectionOption + .ENABLE_WEBVIEW_DETAILS_COLLECTION_OPTION + ) + ); + assertEquals("America/New_York", capMap.get("appium:" + SupportsTimeZoneOption.TIME_ZONE_OPTION)); + assertEquals( + true, + capMap.get( + "appium:" + + SupportsEnableAccessibilityEventsServiceOption + .ENABLE_ACCESSIBILITY_EVENTS_SERVICE_OPTION + ) + ); + assertEquals( + true, + capMap.get("appium:" + SupportsSkipSettingsAppReinstallOption.SKIP_SETTINGS_APP_REINSTALL_OPTION) + ); + } + + @Test + void espressoChainedMethodsPopulateCapabilities() { + var options = new EspressoOptions() + .enableBiDi() + .adbListenAllNetwork() + .allowOfflineDevices() + .dontStopAppOnReset() + .setAutoWebviewName("com.example.espresso") + .chromedriverForwardBiDi() + .chromedriverGrantPermissions() + .disableWebviewDetailsCollection() + .setTimeZone("Asia/Ho_Chi_Minh") + .skipSettingsAppReinstall(); + + assertEquals(Optional.of(true), options.getWebSocketUrl()); + assertEquals(Optional.of(true), options.doesAdbListenAllNetwork()); + assertEquals(Optional.of(true), options.doesAllowOfflineDevices()); + assertEquals(Optional.of(true), options.doesDontStopAppOnReset()); + assertEquals(Optional.of("com.example.espresso"), options.getAutoWebviewName()); + assertEquals(Optional.of(true), options.doesChromedriverForwardBiDi()); + assertEquals(Optional.of(true), options.doesChromedriverGrantPermissions()); + assertEquals(Optional.of(false), options.doesEnableWebviewDetailsCollection()); + assertEquals(Optional.of("Asia/Ho_Chi_Minh"), options.getTimeZone()); + assertEquals(Optional.of(true), options.doesSkipSettingsAppReinstall()); + + Map capMap = options.asMap(); + assertEquals(true, capMap.get("appium:adbListenAllNetwork")); + assertEquals(true, capMap.get("appium:allowOfflineDevices")); + assertEquals(true, capMap.get("appium:dontStopAppOnReset")); + assertEquals("com.example.espresso", capMap.get("appium:autoWebviewName")); + assertEquals(true, capMap.get("appium:chromedriverForwardBiDi")); + assertEquals(true, capMap.get("appium:chromedriverGrantPermissions")); + assertEquals(false, capMap.get("appium:enableWebviewDetailsCollection")); + assertEquals("Asia/Ho_Chi_Minh", capMap.get("appium:timeZone")); + assertEquals(true, capMap.get("appium:skipSettingsAppReinstall")); + } + + @Test + void booleanSettersSupportFalseAndTrueOverrides() { + var uia2 = new UiAutomator2Options() + .setAdbListenAllNetwork(false) + .setAllowOfflineDevices(false) + .setDontStopAppOnReset(false) + .setForceAppLaunch(false) + .setShouldTerminateApp(false) + .setChromedriverForwardBiDi(false) + .setChromedriverGrantPermissions(false) + .setEnableWebviewDetailsCollection(false) + .setEnableAccessibilityEventsService(false) + .setSkipSettingsAppReinstall(false); + + assertEquals(Optional.of(false), uia2.doesAdbListenAllNetwork()); + assertEquals(Optional.of(false), uia2.doesAllowOfflineDevices()); + assertEquals(Optional.of(false), uia2.doesDontStopAppOnReset()); + assertEquals(Optional.of(false), uia2.doesForceAppLaunch()); + assertEquals(Optional.of(false), uia2.doesTerminateApp()); + assertEquals(Optional.of(false), uia2.doesChromedriverForwardBiDi()); + assertEquals(Optional.of(false), uia2.doesChromedriverGrantPermissions()); + assertEquals(Optional.of(false), uia2.doesEnableWebviewDetailsCollection()); + assertEquals(Optional.of(false), uia2.doesEnableAccessibilityEventsService()); + assertEquals(Optional.of(false), uia2.doesSkipSettingsAppReinstall()); + + uia2.setEnableAccessibilityEventsService(true) + .setEnableWebviewDetailsCollection(true) + .setForceAppLaunch(true) + .setShouldTerminateApp(true); + assertTrue(uia2.doesEnableAccessibilityEventsService().orElse(false)); + assertTrue(uia2.doesEnableWebviewDetailsCollection().orElse(false)); + assertTrue(uia2.doesForceAppLaunch().orElse(false)); + assertTrue(uia2.doesTerminateApp().orElse(false)); + + var espresso = new EspressoOptions() + .setAdbListenAllNetwork(false) + .setAllowOfflineDevices(false) + .setDontStopAppOnReset(false) + .setChromedriverForwardBiDi(false) + .setChromedriverGrantPermissions(false) + .setEnableWebviewDetailsCollection(false) + .setSkipSettingsAppReinstall(false); + + assertEquals(Optional.of(false), espresso.doesAdbListenAllNetwork()); + assertEquals(Optional.of(false), espresso.doesAllowOfflineDevices()); + assertEquals(Optional.of(false), espresso.doesDontStopAppOnReset()); + assertEquals(Optional.of(false), espresso.doesChromedriverForwardBiDi()); + assertEquals(Optional.of(false), espresso.doesChromedriverGrantPermissions()); + assertEquals(Optional.of(false), espresso.doesEnableWebviewDetailsCollection()); + assertEquals(Optional.of(false), espresso.doesSkipSettingsAppReinstall()); + + espresso.setChromedriverForwardBiDi(true) + .setEnableWebviewDetailsCollection(true) + .setSkipSettingsAppReinstall(true); + assertTrue(espresso.doesChromedriverForwardBiDi().orElse(false)); + assertTrue(espresso.doesEnableWebviewDetailsCollection().orElse(false)); + assertTrue(espresso.doesSkipSettingsAppReinstall().orElse(false)); + } + + @Test + void copyConstructorsCoerceAndPreserveNewOptions() { + var uia2 = new UiAutomator2Options(Map.ofEntries( + Map.entry("adbListenAllNetwork", "true"), + Map.entry("appium:allowOfflineDevices", "false"), + Map.entry("dontStopAppOnReset", true), + Map.entry("forceAppLaunch", "true"), + Map.entry("shouldTerminateApp", "false"), + Map.entry("autoWebviewName", "chrome"), + Map.entry("chromedriverForwardBiDi", "true"), + Map.entry("chromedriverGrantPermissions", true), + Map.entry("enableWebviewDetailsCollection", "false"), + Map.entry("timeZone", "UTC"), + Map.entry("enableAccessibilityEventsService", "true"), + Map.entry("skipSettingsAppReinstall", "true") + )); + + assertEquals(Optional.of(true), uia2.doesAdbListenAllNetwork()); + assertEquals(Optional.of(false), uia2.doesAllowOfflineDevices()); + assertEquals(Optional.of(true), uia2.doesDontStopAppOnReset()); + assertEquals(Optional.of(true), uia2.doesForceAppLaunch()); + assertEquals(Optional.of(false), uia2.doesTerminateApp()); + assertEquals(Optional.of("chrome"), uia2.getAutoWebviewName()); + assertEquals(Optional.of(true), uia2.doesChromedriverForwardBiDi()); + assertEquals(Optional.of(true), uia2.doesChromedriverGrantPermissions()); + assertEquals(Optional.of(false), uia2.doesEnableWebviewDetailsCollection()); + assertEquals(Optional.of("UTC"), uia2.getTimeZone()); + assertEquals(Optional.of(true), uia2.doesEnableAccessibilityEventsService()); + assertEquals(Optional.of(true), uia2.doesSkipSettingsAppReinstall()); + + var espresso = new EspressoOptions(new ImmutableCapabilities(Map.of( + "appium:chromedriverForwardBiDi", true, + "appium:skipSettingsAppReinstall", true, + "appium:timeZone", "Europe/London", + "appium:autoWebviewName", "com.example.app" + ))); + assertEquals(Optional.of(true), espresso.doesChromedriverForwardBiDi()); + assertEquals(Optional.of(true), espresso.doesSkipSettingsAppReinstall()); + assertEquals(Optional.of("Europe/London"), espresso.getTimeZone()); + assertEquals(Optional.of("com.example.app"), espresso.getAutoWebviewName()); + } +}