From 5e0efa6b80f2c7bf1a82f846e364593dffafaf0c Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 25 Oct 2021 12:47:33 +0200 Subject: [PATCH 1/3] chore: Add more UiAutomator2 options --- .../android/options/UiAutomator2Options.java | 56 ++++++++++++-- .../adb/SupportsAdbExecTimeoutOption.java | 51 +++++++++++++ .../options/adb/SupportsAdbPortOption.java | 49 ++++++++++++ .../adb/SupportsAllowDelayAdbOption.java | 50 +++++++++++++ .../adb/SupportsBuildToolsVersionOption.java | 51 +++++++++++++ .../SupportsClearDeviceLogsOnStartOption.java | 62 ++++++++++++++++ ...portsIgnoreHiddenApiPolicyErrorOption.java | 60 +++++++++++++++ .../adb/SupportsLogcatFilterSpecsOption.java | 51 +++++++++++++ .../adb/SupportsLogcatFormatOption.java | 48 ++++++++++++ .../adb/SupportsMockLocationAppOption.java | 51 +++++++++++++ .../adb/SupportsRemoteAdbHostOption.java | 48 ++++++++++++ .../adb/SupportsSkipLogcatCaptureOption.java | 60 +++++++++++++++ .../adb/SupportsSuppressKillServerOption.java | 59 +++++++++++++++ .../options/avd/SupportsAvdArgsOption.java | 64 ++++++++++++++++ .../options/avd/SupportsAvdEnvOption.java | 50 +++++++++++++ .../avd/SupportsAvdLaunchTimeoutOption.java | 53 +++++++++++++ .../options/avd/SupportsAvdOption.java | 50 +++++++++++++ .../avd/SupportsAvdReadyTimeoutOption.java | 53 +++++++++++++ .../options/avd/SupportsGpsEnabledOption.java | 50 +++++++++++++ .../options/avd/SupportsIsHeadlessOption.java | 51 +++++++++++++ .../avd/SupportsNetworkSpeedOption.java | 50 +++++++++++++ .../SupportsLocaleScriptOption.java | 49 ++++++++++++ .../options/signing/KeystoreConfig.java | 56 ++++++++++++++ .../signing/SupportsKeystoreOptions.java | 74 +++++++++++++++++++ .../options/signing/SupportsNoSignOption.java | 63 ++++++++++++++++ 25 files changed, 1354 insertions(+), 5 deletions(-) create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsAdbExecTimeoutOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsAdbPortOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsAllowDelayAdbOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsBuildToolsVersionOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsClearDeviceLogsOnStartOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsIgnoreHiddenApiPolicyErrorOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFilterSpecsOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFormatOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsMockLocationAppOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsRemoteAdbHostOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsSkipLogcatCaptureOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/adb/SupportsSuppressKillServerOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsAvdArgsOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsAvdEnvOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsAvdLaunchTimeoutOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsAvdOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsAvdReadyTimeoutOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/avd/SupportsNetworkSpeedOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/localization/SupportsLocaleScriptOption.java create mode 100644 src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java create mode 100644 src/main/java/io/appium/java_client/android/options/signing/SupportsKeystoreOptions.java create mode 100644 src/main/java/io/appium/java_client/android/options/signing/SupportsNoSignOption.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 c228e917f..f13dda020 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 @@ -16,6 +16,18 @@ package io.appium.java_client.android.options; +import io.appium.java_client.android.options.adb.SupportsAdbExecTimeoutOption; +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.SupportsBuildToolsVersionOption; +import io.appium.java_client.android.options.adb.SupportsClearDeviceLogsOnStartOption; +import io.appium.java_client.android.options.adb.SupportsIgnoreHiddenApiPolicyErrorOption; +import io.appium.java_client.android.options.adb.SupportsLogcatFilterSpecsOption; +import io.appium.java_client.android.options.adb.SupportsLogcatFormatOption; +import io.appium.java_client.android.options.adb.SupportsMockLocationAppOption; +import io.appium.java_client.android.options.adb.SupportsRemoteAdbHostOption; +import io.appium.java_client.android.options.adb.SupportsSkipLogcatCaptureOption; +import io.appium.java_client.android.options.adb.SupportsSuppressKillServerOption; import io.appium.java_client.android.options.app.SupportsAllowTestPackagesOption; import io.appium.java_client.android.options.app.SupportsAndroidInstallTimeoutOption; import io.appium.java_client.android.options.app.SupportsAppActivityOption; @@ -32,6 +44,15 @@ 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.SupportsUninstallOtherPackagesOption; +import io.appium.java_client.android.options.avd.SupportsAvdArgsOption; +import io.appium.java_client.android.options.avd.SupportsAvdEnvOption; +import io.appium.java_client.android.options.avd.SupportsAvdLaunchTimeoutOption; +import io.appium.java_client.android.options.avd.SupportsAvdOption; +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.SupportsIsHeadlessOption; +import io.appium.java_client.android.options.avd.SupportsNetworkSpeedOption; +import io.appium.java_client.android.options.localization.SupportsLocaleScriptOption; 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; @@ -39,6 +60,8 @@ import io.appium.java_client.android.options.server.SupportsUiautomator2ServerInstallTimeoutOption; import io.appium.java_client.android.options.server.SupportsUiautomator2ServerLaunchTimeoutOption; import io.appium.java_client.android.options.server.SupportsUiautomator2ServerReadTimeoutOption; +import io.appium.java_client.android.options.signing.SupportsKeystoreOptions; +import io.appium.java_client.android.options.signing.SupportsNoSignOption; import io.appium.java_client.remote.AutomationName; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.remote.options.BaseOptions; @@ -58,9 +81,6 @@ * https://github.com/appium/appium-uiautomator2-driver#capabilities */ public class UiAutomator2Options extends BaseOptions implements - // TODO: ADB options: https://github.com/appium/appium-uiautomator2-driver#adb - // TODO: AVD options: https://github.com/appium/appium-uiautomator2-driver#emulator-android-virtual-device - // TODO: App signing options: https://github.com/appium/appium-uiautomator2-driver#app-signing // TODO: Device locking options: https://github.com/appium/appium-uiautomator2-driver#device-locking // TODO: MJPEG options: https://github.com/appium/appium-uiautomator2-driver#mjpeg // TODO: Web Context options: https://github.com/appium/appium-uiautomator2-driver#web-context @@ -100,9 +120,35 @@ public class UiAutomator2Options extends BaseOptions implem SupportsAllowTestPackagesOption, SupportsRemoteAppsCacheLimitOption, SupportsEnforceAppInstallOption, - // TODO: App localization options: https://github.com/appium/appium-uiautomator2-driver#app-localization + // App localization options: https://github.com/appium/appium-uiautomator2-driver#app-localization + SupportsLocaleScriptOption, SupportsLanguageOption, - SupportsLocaleOption { + SupportsLocaleOption, + // ADB options: https://github.com/appium/appium-uiautomator2-driver#adb + SupportsAdbPortOption, + SupportsRemoteAdbHostOption, + SupportsAdbExecTimeoutOption, + SupportsClearDeviceLogsOnStartOption, + SupportsBuildToolsVersionOption, + SupportsSkipLogcatCaptureOption, + SupportsSuppressKillServerOption, + SupportsIgnoreHiddenApiPolicyErrorOption, + SupportsMockLocationAppOption, + SupportsLogcatFormatOption, + SupportsLogcatFilterSpecsOption, + SupportsAllowDelayAdbOption, + // AVD options: https://github.com/appium/appium-uiautomator2-driver#emulator-android-virtual-device + SupportsAvdOption, + SupportsAvdLaunchTimeoutOption, + SupportsAvdReadyTimeoutOption, + SupportsAvdArgsOption, + SupportsAvdEnvOption, + SupportsNetworkSpeedOption, + SupportsGpsEnabledOption, + SupportsIsHeadlessOption, + // App signing options: https://github.com/appium/appium-uiautomator2-driver#app-signing + SupportsKeystoreOptions, + SupportsNoSignOption { public UiAutomator2Options() { setCommonOptions(); } diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbExecTimeoutOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbExecTimeoutOption.java new file mode 100644 index 000000000..228ab056e --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbExecTimeoutOption.java @@ -0,0 +1,51 @@ +/* + * 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.time.Duration; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toDuration; + +public interface SupportsAdbExecTimeoutOption> extends + Capabilities, CanSetCapability { + String ADB_EXEC_TIMEOUT_OPTION = "adbExecTimeout"; + + /** + * Maximum time to wait until single ADB command is executed. + * 20000 ms by default. + * + * @param timeout ADB commands timeout. + * @return self instance for chaining. + */ + default T setAdbExecTimeout(Duration timeout) { + return amend(ADB_EXEC_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get maximum time to wait until single ADB command is executed. + * + * @return Timeout value. + */ + default Optional getAdbExecTimeout() { + return Optional.ofNullable(toDuration(getCapability(ADB_EXEC_TIMEOUT_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbPortOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbPortOption.java new file mode 100644 index 000000000..461e609ab --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsAdbPortOption.java @@ -0,0 +1,49 @@ +/* + * 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.toInteger; + +public interface SupportsAdbPortOption> extends + Capabilities, CanSetCapability { + String ADB_PORT_OPTION = "adbPort"; + + /** + * Set number of the port where ADB is running. 5037 by default + * + * @param port port number in range 0..65535 + * @return self instance for chaining. + */ + default T setAdbPort(int port) { + return amend(ADB_PORT_OPTION, port); + } + + /** + * Get number of the port where ADB is running. + * + * @return Adb port value + */ + default Optional getAdbPort() { + return Optional.ofNullable(toInteger(getCapability(ADB_PORT_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsAllowDelayAdbOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsAllowDelayAdbOption.java new file mode 100644 index 000000000..fc8ea3b80 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsAllowDelayAdbOption.java @@ -0,0 +1,50 @@ +/* + * 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; + +public interface SupportsAllowDelayAdbOption> extends + Capabilities, CanSetCapability { + String ALLOW_DELAY_ADB_OPTION = "allowDelayAdb"; + + /** + * Being set to false prevents emulator to use -delay-adb feature to detect its startup. + * See https://github.com/appium/appium/issues/14773 for more details. + * + * @param value Set it to false in order to prevent the emulator to use -delay-adb feature. + * @return self instance for chaining. + */ + default T setAllowDelayAdb(boolean value) { + return amend(ALLOW_DELAY_ADB_OPTION, value); + } + + /** + * Get whether to prevent the emulator to use -delay-adb feature. + * + * @return True or false. + */ + default Optional doesAllowDelayAdb() { + return Optional.ofNullable(toSafeBoolean(getCapability(ALLOW_DELAY_ADB_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsBuildToolsVersionOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsBuildToolsVersionOption.java new file mode 100644 index 000000000..df5b27f5a --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsBuildToolsVersionOption.java @@ -0,0 +1,51 @@ +/* + * 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; + +public interface SupportsBuildToolsVersionOption> extends + Capabilities, CanSetCapability { + String BUILD_TOOLS_VERSION_OPTION = "buildToolsVersion"; + + /** + * The version of Android build tools to use. By default, UiAutomator2 + * driver uses the most recent version of build tools installed on + * the machine, but sometimes it might be necessary to give it a hint + * (let say if there is a known bug in the most recent tools version). + * Example: 28.0.3 + * + * @param version The build tools version to use. + * @return self instance for chaining. + */ + default T setBuildToolsVersion(String version) { + return amend(BUILD_TOOLS_VERSION_OPTION, version); + } + + /** + * Get the version of Android build tools to use. + * + * @return Build tools version. + */ + default Optional getBuildToolsVersion() { + return Optional.ofNullable((String) getCapability(BUILD_TOOLS_VERSION_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsClearDeviceLogsOnStartOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsClearDeviceLogsOnStartOption.java new file mode 100644 index 000000000..f48891388 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsClearDeviceLogsOnStartOption.java @@ -0,0 +1,62 @@ +/* + * 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; + +public interface SupportsClearDeviceLogsOnStartOption> extends + Capabilities, CanSetCapability { + String CLEAR_DEVICE_LOGS_ON_START_OPTION = "clearDeviceLogsOnStart"; + + /** + * Makes UiAutomator2 to delete all the existing logs in the + * device buffer before starting a new test. + * + * @return self instance for chaining. + */ + default T clearDeviceLogsOnStart() { + return amend(CLEAR_DEVICE_LOGS_ON_START_OPTION, true); + } + + + /** + * If set to true then UiAutomator2 deletes all the existing logs in the + * device buffer before starting a new test. + * + * @param value Set to false if you don't want to wait for the app to finish its launch. + * @return self instance for chaining. + */ + default T setClearDeviceLogsOnStart(boolean value) { + return amend(CLEAR_DEVICE_LOGS_ON_START_OPTION, value); + } + + /** + * Get whether to delete all the existing logs in the + * device buffer before starting a new test. + * + * @return True or false. + */ + default Optional doesClearDeviceLogsOnStart() { + return Optional.ofNullable(toSafeBoolean(getCapability(CLEAR_DEVICE_LOGS_ON_START_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsIgnoreHiddenApiPolicyErrorOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsIgnoreHiddenApiPolicyErrorOption.java new file mode 100644 index 000000000..29999e21d --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsIgnoreHiddenApiPolicyErrorOption.java @@ -0,0 +1,60 @@ +/* + * 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; + +public interface SupportsIgnoreHiddenApiPolicyErrorOption> extends + Capabilities, CanSetCapability { + String IGNORE_HIDDEN_API_POLICY_ERROR_OPTION = "ignoreHiddenApiPolicyError"; + + /** + * Prevents the driver from ever killing the ADB server explicitl. + * + * @return self instance for chaining. + */ + default T ignoreHiddenApiPolicyError() { + return amend(IGNORE_HIDDEN_API_POLICY_ERROR_OPTION, true); + } + + /** + * Being set to true ignores a failure while changing hidden API access policies. + * Could be useful on some devices, where access to these policies has been locked by its vendor. + * false by default. + * + * @param value Whether to ignore a failure while changing hidden API access policies. + * @return self instance for chaining. + */ + default T setIgnoreHiddenApiPolicyError(boolean value) { + return amend(IGNORE_HIDDEN_API_POLICY_ERROR_OPTION, value); + } + + /** + * Get whether to ignore a failure while changing hidden API access policies. + * + * @return True or false. + */ + default Optional doesIgnoreHiddenApiPolicyError() { + return Optional.ofNullable(toSafeBoolean(getCapability(IGNORE_HIDDEN_API_POLICY_ERROR_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFilterSpecsOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFilterSpecsOption.java new file mode 100644 index 000000000..6aca7a15e --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFilterSpecsOption.java @@ -0,0 +1,51 @@ +/* + * 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; + +public interface SupportsLogcatFilterSpecsOption> extends + Capabilities, CanSetCapability { + String LOGCAT_FILTER_SPECS_OPTION = "logcatFilterSpecs"; + + /** + * Series of tag[:priority] where tag is a log component tag (or * for all) + * and priority is: V Verbose, D Debug, I Info, W Warn, E Error, F Fatal, + * S Silent (supress all output). '' means ':d' and tag by itself means tag:v. + * If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS. + * If no filterspec is found, filter defaults to '*:I'. + * + * @param format The filter specifier. + * @return self instance for chaining. + */ + default T setLogcatFilterSpecs(String format) { + return amend(LOGCAT_FILTER_SPECS_OPTION, format); + } + + /** + * Get the logcat filter format. + * + * @return Format specifier. + */ + default Optional getLogcatFilterSpecs() { + return Optional.ofNullable((String) getCapability(LOGCAT_FILTER_SPECS_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFormatOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFormatOption.java new file mode 100644 index 000000000..98302419e --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsLogcatFormatOption.java @@ -0,0 +1,48 @@ +/* + * 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; + +public interface SupportsLogcatFormatOption> extends + Capabilities, CanSetCapability { + String LOGCAT_FORMAT_OPTION = "logcatFormat"; + + /** + * The log print format, where format is one of: brief process tag thread raw time + * threadtime long. threadtime is the default value. + * + * @param format The format specifier. + * @return self instance for chaining. + */ + default T setLogcatFormat(String format) { + return amend(LOGCAT_FORMAT_OPTION, format); + } + + /** + * Get the log print format. + * + * @return Format specifier. + */ + default Optional getLogcatFormat() { + return Optional.ofNullable((String) getCapability(LOGCAT_FORMAT_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsMockLocationAppOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsMockLocationAppOption.java new file mode 100644 index 000000000..e0b690f38 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsMockLocationAppOption.java @@ -0,0 +1,51 @@ +/* + * 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; + +public interface SupportsMockLocationAppOption> extends + Capabilities, CanSetCapability { + String MOCK_LOCATION_APP_OPTION = "mockLocationApp"; + + /** + * Sets the package identifier of the app, which is used as a system mock location + * provider since Appium 1.18.0+. This capability has no effect on emulators. + * If the value is set to null or an empty string, then Appium will skip the mocked + * location provider setup procedure. Defaults to Appium Setting package + * identifier (io.appium.settings). + * + * @param appIdentifier The identifier of the mock location provider app. + * @return self instance for chaining. + */ + default T setMockLocationApp(String appIdentifier) { + return amend(MOCK_LOCATION_APP_OPTION, appIdentifier); + } + + /** + * Get the identifier of the app, which is used as a system mock location provider. + * + * @return App identifier. + */ + default Optional getMockLocationApp() { + return Optional.ofNullable((String) getCapability(MOCK_LOCATION_APP_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsRemoteAdbHostOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsRemoteAdbHostOption.java new file mode 100644 index 000000000..6e8c94a1d --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsRemoteAdbHostOption.java @@ -0,0 +1,48 @@ +/* + * 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; + +public interface SupportsRemoteAdbHostOption> extends + Capabilities, CanSetCapability { + String REMOTE_ADB_HOST_OPTION = "remoteAdbHost"; + + /** + * Address of the host where ADB is running (the value of -H ADB command line option). + * Localhost by default. + * + * @param host The name host where ADB server is running. + * @return self instance for chaining. + */ + default T setRemoteAdbHost(String host) { + return amend(REMOTE_ADB_HOST_OPTION, host); + } + + /** + * Get the address of the host where ADB is running. + * + * @return Host name. + */ + default Optional getRemoteAdbHost() { + return Optional.ofNullable((String) getCapability(REMOTE_ADB_HOST_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsSkipLogcatCaptureOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsSkipLogcatCaptureOption.java new file mode 100644 index 000000000..1bd0f6b42 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsSkipLogcatCaptureOption.java @@ -0,0 +1,60 @@ +/* + * 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; + +public interface SupportsSkipLogcatCaptureOption> extends + Capabilities, CanSetCapability { + String SKIP_LOGCAT_CAPTURE_OPTION = "skipLogcatCapture"; + + /** + * Disables automatic logcat output collection during the test run. + * + * @return self instance for chaining. + */ + default T skipLogcatCapture() { + return amend(SKIP_LOGCAT_CAPTURE_OPTION, true); + } + + /** + * Being set to true disables automatic logcat output collection during the test run. + * false by default + * + * @param value Whether to delete all the existing device logs before starting a new test. + * @return self instance for chaining. + */ + default T setSkipLogcatCapture(boolean value) { + return amend(SKIP_LOGCAT_CAPTURE_OPTION, value); + } + + /** + * Get whether to delete all the existing logs in the + * device buffer before starting a new test. + * + * @return True or false. + */ + default Optional doesSkipLogcatCapture() { + return Optional.ofNullable(toSafeBoolean(getCapability(SKIP_LOGCAT_CAPTURE_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/adb/SupportsSuppressKillServerOption.java b/src/main/java/io/appium/java_client/android/options/adb/SupportsSuppressKillServerOption.java new file mode 100644 index 000000000..daaa9666b --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/adb/SupportsSuppressKillServerOption.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.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; + +public interface SupportsSuppressKillServerOption> extends + Capabilities, CanSetCapability { + String SUPPRESS_KILL_SERVER_OPTION = "suppressKillServer"; + + /** + * Prevents the driver from ever killing the ADB server explicitl. + * + * @return self instance for chaining. + */ + default T suppressKillServer() { + return amend(SUPPRESS_KILL_SERVER_OPTION, true); + } + + /** + * Being set to true prevents the driver from ever killing the ADB server explicitly. + * Could be useful if ADB is connected wirelessly. false by default. + * + * @param value Whether to prevent the driver from ever killing the ADB server explicitly. + * @return self instance for chaining. + */ + default T setSuppressKillServer(boolean value) { + return amend(SUPPRESS_KILL_SERVER_OPTION, value); + } + + /** + * Get whether to prevent the driver from ever killing the ADB server explicitly. + * + * @return True or false. + */ + default Optional doesSuppressKillServer() { + return Optional.ofNullable(toSafeBoolean(getCapability(SUPPRESS_KILL_SERVER_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdArgsOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdArgsOption.java new file mode 100644 index 000000000..7843393e4 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdArgsOption.java @@ -0,0 +1,64 @@ +/* + * 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.avd; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.internal.Either; + +import java.util.List; +import java.util.Optional; + +public interface SupportsAvdArgsOption> extends + Capabilities, CanSetCapability { + String AVD_ARGS_OPTION = "avdArgs"; + + /** + * Set emulator command line arguments. + * + * @param args Emulator command line arguments. + * @return self instance for chaining. + */ + default T setAvdArgs(List args) { + return amend(AVD_ARGS_OPTION, args); + } + + /** + * Set emulator command line arguments. + * + * @param args Emulator command line arguments. + * @return self instance for chaining. + */ + default T setAvdArgs(String args) { + return amend(AVD_ARGS_OPTION, args); + } + + /** + * Get emulator command line arguments. + * + * @return Either arguments list of command line string. + */ + default Optional, String>> getAvdArgs() { + //noinspection unchecked + return Optional.ofNullable(getCapability(AVD_ARGS_OPTION)) + .map((v) -> v instanceof List + ? Either.left((List) v) + : Either.right(String.valueOf(v)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdEnvOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdEnvOption.java new file mode 100644 index 000000000..e6d083aee --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdEnvOption.java @@ -0,0 +1,50 @@ +/* + * 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.avd; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Map; +import java.util.Optional; + +public interface SupportsAvdEnvOption> extends + Capabilities, CanSetCapability { + String AVD_ENV_OPTION = "avdEnv"; + + /** + * Set the mapping of emulator environment variables. + * + * @param env Emulator environment variables mapping. + * @return self instance for chaining. + */ + default T setAvdEnv(Map env) { + return amend(AVD_ENV_OPTION, env); + } + + /** + * Get the mapping of emulator environment variables. + * + * @return Emulator environment variables mapping. + */ + default Optional> getAvdEnv() { + //noinspection unchecked + return Optional.ofNullable(getCapability(AVD_ENV_OPTION)) + .map((v) -> (Map) v); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdLaunchTimeoutOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdLaunchTimeoutOption.java new file mode 100644 index 000000000..974b02203 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdLaunchTimeoutOption.java @@ -0,0 +1,53 @@ +/* + * 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.avd; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.time.Duration; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toDuration; + +public interface SupportsAvdLaunchTimeoutOption> extends + Capabilities, CanSetCapability { + String AVD_LAUNCH_TIMEOUT_OPTION = "avdLaunchTimeout"; + + /** + * Maximum timeout to wait until Android Emulator is started. + * 60000 ms by default. + * + * @param timeout Timeout value. + * @return self instance for chaining. + */ + default T setAvdLaunchTimeout(Duration timeout) { + return amend(AVD_LAUNCH_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the timeout to wait until Android Emulator is started. + * + * @return The timeout value. + */ + default Optional getAvdLaunchTimeout() { + return Optional.ofNullable( + toDuration(getCapability(AVD_LAUNCH_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdOption.java new file mode 100644 index 000000000..8eac74bd4 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdOption.java @@ -0,0 +1,50 @@ +/* + * 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.avd; + +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; + +public interface SupportsAvdOption> extends + Capabilities, CanSetCapability { + String AVD_OPTION = "avd"; + + /** + * The name of Android emulator to run the test on. + * The names of currently installed emulators could be listed using + * avdmanager list avd command. If the emulator with the given name + * is not running then it is going to be started before a test. + * + * @param avd The emulator name to use. + * @return self instance for chaining. + */ + default T setAvd(String avd) { + return amend(AVD_OPTION, avd); + } + + /** + * Get the name of Android emulator to run the test on. + * + * @return Emulator name. + */ + default Optional getAvd() { + return Optional.ofNullable((String) getCapability(AVD_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdReadyTimeoutOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdReadyTimeoutOption.java new file mode 100644 index 000000000..68f1e27f2 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsAvdReadyTimeoutOption.java @@ -0,0 +1,53 @@ +/* + * 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.avd; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.time.Duration; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toDuration; + +public interface SupportsAvdReadyTimeoutOption> extends + Capabilities, CanSetCapability { + String AVD_READY_TIMEOUT_OPTION = "avdReadyTimeout"; + + /** + * Maximum timeout to wait until Android Emulator is fully booted and is ready for usage. + * 60000 ms by default + * + * @param timeout Timeout value. + * @return self instance for chaining. + */ + default T setAvdReadyTimeout(Duration timeout) { + return amend(AVD_READY_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the timeout to wait until Android Emulator is fully booted and is ready for usage. + * + * @return The timeout value. + */ + default Optional getAvdReadyTimeout() { + return Optional.ofNullable( + toDuration(getCapability(AVD_READY_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java new file mode 100644 index 000000000..6f644e6f2 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java @@ -0,0 +1,50 @@ +/* + * 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.avd; + +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; + +public interface SupportsGpsEnabledOption> extends + Capabilities, CanSetCapability { + String GPS_ENABLED_OPTION = "gpsEnabled"; + + /** + * Sets whether to enable (true) or disable (false) GPS service in the Emulator. + * Unset by default, which means to not change the current value. + * + * @param value Whether to enable or disable the GPS service. + * @return self instance for chaining. + */ + default T setGpsEnabled(boolean value) { + return amend(GPS_ENABLED_OPTION, value); + } + + /** + * Get the state of GPS service on emulator. + * + * @return True or false. + */ + default Optional getGpsEnabled() { + return Optional.ofNullable(toSafeBoolean(getCapability(GPS_ENABLED_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java new file mode 100644 index 000000000..5325ceb3f --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java @@ -0,0 +1,51 @@ +/* + * 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.avd; + +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; + +public interface SupportsIsHeadlessOption> extends + Capabilities, CanSetCapability { + String IS_HEADLESS_OPTION = "isHeadless"; + + /** + * If set to true then emulator starts in headless mode (e.g. no UI is shown). + * It is only applied if the emulator is not running before the test starts. + * false by default. + * + * @param value Whether to enable or disable headless mode. + * @return self instance for chaining. + */ + default T setIsHeadless(boolean value) { + return amend(IS_HEADLESS_OPTION, value); + } + + /** + * Get whether the emulator starts in headless mode. + * + * @return True or false. + */ + default Optional isHeadless() { + return Optional.ofNullable(toSafeBoolean(getCapability(IS_HEADLESS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsNetworkSpeedOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsNetworkSpeedOption.java new file mode 100644 index 000000000..5a3d05b47 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsNetworkSpeedOption.java @@ -0,0 +1,50 @@ +/* + * 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.avd; + +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; + +public interface SupportsNetworkSpeedOption> extends + Capabilities, CanSetCapability { + String NETWORK_SPEED_OPTION = "networkSpeed"; + + /** + * Sets the desired network speed limit for the emulator. + * It is only applied if the emulator is not running before + * the test starts. See emulator command line arguments description + * for more details. + * + * @param speed Speed value. + * @return self instance for chaining. + */ + default T setNetworkSpeed(String speed) { + return amend(NETWORK_SPEED_OPTION, speed); + } + + /** + * Get the desired network speed limit for the emulator. + * + * @return Speed value. + */ + default Optional getNetworkSpeed() { + return Optional.ofNullable((String) getCapability(NETWORK_SPEED_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/localization/SupportsLocaleScriptOption.java b/src/main/java/io/appium/java_client/android/options/localization/SupportsLocaleScriptOption.java new file mode 100644 index 000000000..835c7d41d --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/localization/SupportsLocaleScriptOption.java @@ -0,0 +1,49 @@ +/* + * 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; + +public interface SupportsLocaleScriptOption> extends + Capabilities, CanSetCapability { + String LOCALE_SCRIPT_OPTION = "localeScript"; + + /** + * Set canonical name of the locale to be set for the app under test, + * for example zh-Hans-CN. + * See https://developer.android.com/reference/java/util/Locale.html for more details. + * + * @param localeScript is the language abbreviation. + * @return this MobileOptions, for chaining. + */ + default T setLocaleScript(String localeScript) { + return amend(LOCALE_SCRIPT_OPTION, localeScript); + } + + /** + * Get canonical name of the locale to be set for the app under test. + * + * @return Locale script value. + */ + default Optional getLocaleScript() { + return Optional.ofNullable((String) getCapability(LOCALE_SCRIPT_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java b/src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java new file mode 100644 index 000000000..a687dd371 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java @@ -0,0 +1,56 @@ +/* + * 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.signing; + +public class KeystoreConfig { + private final String path; + private final String password; + private final String keyAlias; + private final String keyPassword; + + /** + * Defines the configuration of a custom keystore. + * + * @param path The full path to the keystore file on the server filesystem. + * @param password The password to the keystore file provided in path. + * @param keyAlias The alias of the key in the keystore file provided in path. + * @param keyPassword The password of the key in the keystore file provided in path. + */ + public KeystoreConfig(String path, String password, + String keyAlias, String keyPassword) { + this.path = path; + this.password = password; + this.keyAlias = keyAlias; + this.keyPassword = keyPassword; + } + + public String getPath() { + return path; + } + + public String getPassword() { + return password; + } + + public String getKeyAlias() { + return keyAlias; + } + + public String getKeyPassword() { + return keyPassword; + } +} diff --git a/src/main/java/io/appium/java_client/android/options/signing/SupportsKeystoreOptions.java b/src/main/java/io/appium/java_client/android/options/signing/SupportsKeystoreOptions.java new file mode 100644 index 000000000..4a79dbc67 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/signing/SupportsKeystoreOptions.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.signing; + +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; + +public interface SupportsKeystoreOptions> extends + Capabilities, CanSetCapability { + String USE_KEYSTORE_OPTION = "useKeystore"; + String KEYSTORE_PATH_OPTION = "keystorePath"; + String KEYSTORE_PASSWORD_OPTION = "keystorePassword"; + String KEY_ALIAS_OPTION = "keyAlias"; + String KEY_PASSWORD_OPTION = "keyPassword"; + + /** + * Use a custom keystore to sign the app under test. + * + * @param keystoreConfig The keystore config to use. + * @return self instance for chaining. + */ + default T useKeystore(KeystoreConfig keystoreConfig) { + return amend(USE_KEYSTORE_OPTION, true) + .amend(KEYSTORE_PATH_OPTION, keystoreConfig.getPath()) + .amend(KEYSTORE_PASSWORD_OPTION, keystoreConfig.getPassword()) + .amend(KEY_ALIAS_OPTION, keystoreConfig.getKeyAlias()) + .amend(KEY_PASSWORD_OPTION, keystoreConfig.getKeyPassword()); + } + + /** + * Get whether to use a custom keystore. + * + * @return True or false. + */ + default Optional doesUseKeystore() { + return Optional.ofNullable(toSafeBoolean(getCapability(USE_KEYSTORE_OPTION))); + } + + /** + * Get the custom keystore config. + * + * @return The keystore config. + */ + default Optional getKeystoreConfig() { + if (!doesUseKeystore().orElse(false)) { + return Optional.empty(); + } + return Optional.of(new KeystoreConfig( + (String) getCapability(KEYSTORE_PATH_OPTION), + (String) getCapability(KEYSTORE_PASSWORD_OPTION), + (String) getCapability(KEY_ALIAS_OPTION), + (String) getCapability(KEY_PASSWORD_OPTION) + )); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/signing/SupportsNoSignOption.java b/src/main/java/io/appium/java_client/android/options/signing/SupportsNoSignOption.java new file mode 100644 index 000000000..9518d7b8f --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/signing/SupportsNoSignOption.java @@ -0,0 +1,63 @@ +/* + * 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.signing; + +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; + +public interface SupportsNoSignOption> extends + Capabilities, CanSetCapability { + String NO_SIGN_OPTION = "noSign"; + + /** + * Skips application signing. + * + * @return self instance for chaining. + */ + default T noSign() { + return amend(NO_SIGN_OPTION, true); + } + + /** + * Set it to true in order to skip application signing. By default, + * all apps are always signed with the default Appium debug signature + * if they don't have any. This capability cancels all the signing checks + * and makes the driver to use the application package as is. This + * capability does not affect .apks packages as these are expected to be + * already signed. + * + * @param value Whether to skip package signing. + * @return self instance for chaining. + */ + default T setNoSign(boolean value) { + return amend(NO_SIGN_OPTION, value); + } + + /** + * Get whether to skip package signing. + * + * @return True or false. + */ + default Optional doesNoSign() { + return Optional.ofNullable(toSafeBoolean(getCapability(NO_SIGN_OPTION))); + } +} From a4c11fff6fb210a67521dbcb50fa243ee7195731 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 25 Oct 2021 13:16:04 +0200 Subject: [PATCH 2/3] Use Lombok --- .../options/signing/KeystoreConfig.java | 37 +++---------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java b/src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java index a687dd371..5ab0d78b6 100644 --- a/src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java +++ b/src/main/java/io/appium/java_client/android/options/signing/KeystoreConfig.java @@ -16,41 +16,14 @@ package io.appium.java_client.android.options.signing; +import lombok.Data; +import lombok.ToString; + +@ToString() +@Data() public class KeystoreConfig { private final String path; private final String password; private final String keyAlias; private final String keyPassword; - - /** - * Defines the configuration of a custom keystore. - * - * @param path The full path to the keystore file on the server filesystem. - * @param password The password to the keystore file provided in path. - * @param keyAlias The alias of the key in the keystore file provided in path. - * @param keyPassword The password of the key in the keystore file provided in path. - */ - public KeystoreConfig(String path, String password, - String keyAlias, String keyPassword) { - this.path = path; - this.password = password; - this.keyAlias = keyAlias; - this.keyPassword = keyPassword; - } - - public String getPath() { - return path; - } - - public String getPassword() { - return password; - } - - public String getKeyAlias() { - return keyAlias; - } - - public String getKeyPassword() { - return keyPassword; - } } From f7f366cce32ae4d67cef481eabe41ac910231718 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 25 Oct 2021 15:57:29 +0200 Subject: [PATCH 3/3] Add boolean setters --- .../android/options/avd/SupportsGpsEnabledOption.java | 10 ++++++++++ .../android/options/avd/SupportsIsHeadlessOption.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java index 6f644e6f2..91dce65da 100644 --- a/src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsGpsEnabledOption.java @@ -28,6 +28,16 @@ public interface SupportsGpsEnabledOption> extends Capabilities, CanSetCapability { String GPS_ENABLED_OPTION = "gpsEnabled"; + /** + * Enables GPS service in the Emulator. + * Unset by default, which means to not change the current value. + * + * @return self instance for chaining. + */ + default T gpsEnabled() { + return amend(GPS_ENABLED_OPTION, true); + } + /** * Sets whether to enable (true) or disable (false) GPS service in the Emulator. * Unset by default, which means to not change the current value. diff --git a/src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java b/src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java index 5325ceb3f..ee365c801 100644 --- a/src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java +++ b/src/main/java/io/appium/java_client/android/options/avd/SupportsIsHeadlessOption.java @@ -28,6 +28,16 @@ public interface SupportsIsHeadlessOption> extends Capabilities, CanSetCapability { String IS_HEADLESS_OPTION = "isHeadless"; + /** + * Set emulator to start in headless mode (e.g. no UI is shown). + * It is only applied if the emulator is not running before the test starts. + * + * @return self instance for chaining. + */ + default T headless() { + return amend(IS_HEADLESS_OPTION, true); + } + /** * If set to true then emulator starts in headless mode (e.g. no UI is shown). * It is only applied if the emulator is not running before the test starts.