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 3514db845..c228e917f 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,29 @@ package io.appium.java_client.android.options; +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; +import io.appium.java_client.android.options.app.SupportsAppDurationOption; +import io.appium.java_client.android.options.app.SupportsAppPackageOption; +import io.appium.java_client.android.options.app.SupportsAppWaitActivityOption; +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.SupportsEnforceAppInstallOption; +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.SupportsUninstallOtherPackagesOption; +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.SupportsSystemPortOption; +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.remote.AutomationName; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.remote.options.BaseOptions; @@ -31,12 +54,55 @@ import io.appium.java_client.remote.options.SupportsUdidOption; import org.openqa.selenium.Capabilities; +/** + * https://github.com/appium/appium-uiautomator2-driver#capabilities + */ public class UiAutomator2Options extends BaseOptions implements - SupportsAppOption, SupportsAutoWebViewOption, - SupportsClearSystemFilesOption, SupportsDeviceNameOption, - SupportsEnablePerformanceLoggingOption, SupportsLanguageOption, - SupportsLocaleOption, SupportsOrientationOption, - SupportsOtherAppsOption, SupportsUdidOption { + // 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 + // TODO: Other options: https://github.com/appium/appium-uiautomator2-driver#other + // TODO: Shared options + SupportsAutoWebViewOption, + // General options: https://github.com/appium/appium-uiautomator2-driver#general + SupportsDeviceNameOption, + SupportsUdidOption, + // Driver/Server options: https://github.com/appium/appium-uiautomator2-driver#driverserver + SupportsSystemPortOption, + SupportsSkipServerInstallationOption, + SupportsUiautomator2ServerLaunchTimeoutOption, + SupportsUiautomator2ServerInstallTimeoutOption, + SupportsUiautomator2ServerReadTimeoutOption, + SupportsDisableWindowAnimationOption, + SupportsSkipDeviceInitializationOption, + SupportsOrientationOption, + SupportsClearSystemFilesOption, + SupportsEnablePerformanceLoggingOption, + // App options: https://github.com/appium/appium-uiautomator2-driver#app + SupportsAppOption, + SupportsAppPackageOption, + SupportsAppActivityOption, + SupportsAppWaitActivityOption, + SupportsAppWaitPackageOption, + SupportsAppDurationOption, + SupportsAndroidInstallTimeoutOption, + SupportsAppWaitForLaunchOption, + SupportsIntentCategoryOption, + SupportsIntentActionOption, + SupportsIntentFlagsOption, + SupportsOptionalIntentArgumentsOption, + SupportsAutoGrantPermissionsOption, + SupportsOtherAppsOption, + SupportsUninstallOtherPackagesOption, + SupportsAllowTestPackagesOption, + SupportsRemoteAppsCacheLimitOption, + SupportsEnforceAppInstallOption, + // TODO: App localization options: https://github.com/appium/appium-uiautomator2-driver#app-localization + SupportsLanguageOption, + SupportsLocaleOption { public UiAutomator2Options() { setCommonOptions(); } diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAllowTestPackagesOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAllowTestPackagesOption.java new file mode 100644 index 000000000..2926aa932 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAllowTestPackagesOption.java @@ -0,0 +1,61 @@ +/* + * 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; + +public interface SupportsAllowTestPackagesOption> extends + Capabilities, CanSetCapability { + String ALLOW_TEST_PACKAGES_OPTION = "allowTestPackages"; + + /** + * Enables usage of packages built with the test flag for + * the automated testing (literally adds -t flag to the adb install command). + * + * @return self instance for chaining. + */ + default T allowTestPackages() { + return amend(ALLOW_TEST_PACKAGES_OPTION, true); + } + + /** + * If set to true then it would be possible to use packages built with the test flag for + * the automated testing (literally adds -t flag to the adb install command). false by default. + * + * @param value True to allow test packages installation. + * @return self instance for chaining. + */ + default T setAllowTestPackages(boolean value) { + return amend(ALLOW_TEST_PACKAGES_OPTION, value); + } + + /** + * Get whether it is possible to use packages built with the test flag for + * the automated testing (literally adds -t flag to the adb install command). + * + * @return True or false. + */ + default Optional doesAllowTestPackages() { + return Optional.ofNullable(toSafeBoolean(getCapability(ALLOW_TEST_PACKAGES_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAndroidInstallTimeoutOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAndroidInstallTimeoutOption.java new file mode 100644 index 000000000..40a588c2e --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAndroidInstallTimeoutOption.java @@ -0,0 +1,54 @@ +/* + * 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.internal.CapabilityHelpers; +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 SupportsAndroidInstallTimeoutOption> extends + Capabilities, CanSetCapability { + String ANDROID_INSTALL_TIMEOUT_OPTION = "androidInstallTimeout"; + + /** + * Maximum amount of time to wait until the application under test is installed. + * 90000 ms by default + * + * @param installTimeout App install timeout. + * @return self instance for chaining. + */ + default T setAndroidInstallTimeout(Duration installTimeout) { + return amend(ANDROID_INSTALL_TIMEOUT_OPTION, installTimeout.toMillis()); + } + + /** + * Get maximum amount of time to wait until the application under test is installed. + * + * @return Timeout value. + */ + default Optional getAndroidInstallTimeout() { + return Optional.ofNullable( + CapabilityHelpers.toDuration(getCapability(ANDROID_INSTALL_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAppActivityOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAppActivityOption.java new file mode 100644 index 000000000..6e1e544bd --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAppActivityOption.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.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; + +public interface SupportsAppActivityOption> extends + Capabilities, CanSetCapability { + String APP_ACTIVITY_OPTION = "appActivity"; + + /** + * Main application activity identifier. If not provided then UiAutomator2 + * will try to detect it automatically from the package provided by the app capability. + * + * @param appActivity Fully qualified app activity class name. + * @return self instance for chaining. + */ + default T setAppActivity(String appActivity) { + return amend(APP_ACTIVITY_OPTION, appActivity); + } + + /** + * Get the name of the main app activity. + * + * @return Activity class name. + */ + default Optional getAppActivity() { + return Optional.ofNullable((String) getCapability(APP_ACTIVITY_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAppDurationOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAppDurationOption.java new file mode 100644 index 000000000..3a3bce7b7 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAppDurationOption.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.app; + +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 SupportsAppDurationOption> extends + Capabilities, CanSetCapability { + String APP_WAIT_DURATION_OPTION = "appWaitDuration"; + + /** + * Maximum amount of time to wait until the application under test is started + * (e.g. an activity returns the control to the caller). 20000 ms by default. + * + * @param appWaitDuration Package identifier to wait for. + * @return self instance for chaining. + */ + default T setAppWaitDuration(Duration appWaitDuration) { + return amend(APP_WAIT_DURATION_OPTION, appWaitDuration.toMillis()); + } + + /** + * Get the identifier of the app package to wait for. + * + * @return Package identifier. + */ + default Optional getAppWaitDuration() { + return Optional.ofNullable(toDuration(getCapability(APP_WAIT_DURATION_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAppPackageOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAppPackageOption.java new file mode 100644 index 000000000..a82cc5dfe --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAppPackageOption.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.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; + +public interface SupportsAppPackageOption> extends + Capabilities, CanSetCapability { + String APP_PACKAGE_OPTION = "appPackage"; + + /** + * Application package identifier to be started. If not provided then UiAutomator2 will + * try to detect it automatically from the package provided by the app capability. + * + * @param appPackage App package identifier. + * @return self instance for chaining. + */ + default T setAppPackage(String appPackage) { + return amend(APP_PACKAGE_OPTION, appPackage); + } + + /** + * Get the app package identifier. + * + * @return Identifier value. + */ + default Optional getAppPackage() { + return Optional.ofNullable((String) getCapability(APP_PACKAGE_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitActivityOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitActivityOption.java new file mode 100644 index 000000000..5567fbb1e --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitActivityOption.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.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; + +public interface SupportsAppWaitActivityOption> extends + Capabilities, CanSetCapability { + String APP_WAIT_ACTIVITY_OPTION = "appWaitActivity"; + + /** + * Identifier of the activity that the driver should wait for + * (not necessarily the main one). + * If not provided then defaults to appium:appActivity. + * + * @param appWaitActivity Fully qualified app activity class name. + * @return self instance for chaining. + */ + default T setAppWaitActivity(String appWaitActivity) { + return amend(APP_WAIT_ACTIVITY_OPTION, appWaitActivity); + } + + /** + * Get the name of the app activity to wait for. + * + * @return Activity class name. + */ + default Optional getAppWaitActivity() { + return Optional.ofNullable((String) getCapability(APP_WAIT_ACTIVITY_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitForLaunchOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitForLaunchOption.java new file mode 100644 index 000000000..70e440b54 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitForLaunchOption.java @@ -0,0 +1,52 @@ +/* + * 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; + +public interface SupportsAppWaitForLaunchOption> extends + Capabilities, CanSetCapability { + String APP_WAIT_FOR_LAUNCH_OPTION = "appWaitForLaunch"; + + /** + * Whether to block until the app under test returns the control to the + * caller after its activity has been started by Activity Manager + * (true, the default value) or to continue the test without waiting for that (false). + * + * @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 setAppWaitForLaunch(boolean value) { + return amend(APP_WAIT_FOR_LAUNCH_OPTION, value); + } + + /** + * Get whether to block until the app under test returns the control to the + * caller after its activity has been started by Activity Manager. + * + * @return True if the driver should block or false otherwise. + */ + default Optional doesAppWaitForLaunch() { + return Optional.ofNullable(toSafeBoolean(getCapability(APP_WAIT_FOR_LAUNCH_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitPackageOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitPackageOption.java new file mode 100644 index 000000000..6089d9bcf --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAppWaitPackageOption.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.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; + +public interface SupportsAppWaitPackageOption> extends + Capabilities, CanSetCapability { + String APP_WAIT_PACKAGE_OPTION = "appWaitPackage"; + + /** + * Identifier of the package that the driver should wait for + * (not necessarily the main one). + * If not provided then defaults to appium:appPackage. + * + * @param appWaitPackage Package identifier to wait for. + * @return self instance for chaining. + */ + default T setAppWaitPackage(String appWaitPackage) { + return amend(APP_WAIT_PACKAGE_OPTION, appWaitPackage); + } + + /** + * Get the identifier of the app package to wait for. + * + * @return Package identifier. + */ + default Optional getAppWaitPackage() { + return Optional.ofNullable((String) getCapability(APP_WAIT_PACKAGE_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsAutoGrantPermissionsOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsAutoGrantPermissionsOption.java new file mode 100644 index 000000000..97402c867 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsAutoGrantPermissionsOption.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.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; + +public interface SupportsAutoGrantPermissionsOption> extends + Capabilities, CanSetCapability { + String AUTO_GRANT_PERMISSIONS_OPTION = "autoGrantPermissions"; + + /** + * Enables granting of all the requested application permissions + * automatically when a test starts. + * + * @return self instance for chaining. + */ + default T setAutoGrantPermissions() { + return amend(AUTO_GRANT_PERMISSIONS_OPTION, true); + } + + + /** + * Whether to grant all the requested application permissions + * automatically when a test starts(true). false by default. + * + * @param value Whether to enable or disable automatic permissions granting. + * @return self instance for chaining. + */ + default T setAutoGrantPermissions(boolean value) { + return amend(AUTO_GRANT_PERMISSIONS_OPTION, value); + } + + /** + * Get whether to grant all the requested application permissions + * automatically when a test starts. + * + * @return True if the permissions should be granted. + */ + default Optional doesAutoGrantPermissions() { + return Optional.ofNullable(toSafeBoolean(getCapability(AUTO_GRANT_PERMISSIONS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsEnforceAppInstallOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsEnforceAppInstallOption.java new file mode 100644 index 000000000..3acc25875 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsEnforceAppInstallOption.java @@ -0,0 +1,61 @@ +/* + * 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; + +public interface SupportsEnforceAppInstallOption> extends + Capabilities, CanSetCapability { + String ENFORCE_APP_INSTALL_OPTION = "enforceAppInstall"; + + /** + * Sets the application under test is always reinstalled even if a newer version + * of it already exists on the device under test. + * + * @return self instance for chaining. + */ + default T enforceAppInstall() { + return amend(ENFORCE_APP_INSTALL_OPTION, true); + } + + /** + * Allows setting whether the application under test is always reinstalled even + * if a newer version of it already exists on the device under test. false by default. + * + * @param value True to allow test packages installation. + * @return self instance for chaining. + */ + default T setEnforceAppInstall(boolean value) { + return amend(ENFORCE_APP_INSTALL_OPTION, value); + } + + /** + * Get whether the application under test is always reinstalled even + * if a newer version of it already exists on the device under test. + * + * @return True or false. + */ + default Optional doesEnforceAppInstall() { + return Optional.ofNullable(toSafeBoolean(getCapability(ENFORCE_APP_INSTALL_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsIntentActionOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsIntentActionOption.java new file mode 100644 index 000000000..7fc2afe89 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsIntentActionOption.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.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; + +public interface SupportsIntentActionOption> extends + Capabilities, CanSetCapability { + String INTENT_ACTION_OPTION = "intentAction"; + + /** + * Set an optional intent action to be applied when + * starting the given appActivity by Activity Manager. + * + * @param intentAction Intent action class name. + * @return self instance for chaining. + */ + default T setIntentAction(String intentAction) { + return amend(INTENT_ACTION_OPTION, intentAction); + } + + /** + * Get intent action to be applied when + * starting the given appActivity by Activity Manager. + * + * @return Intent action class name. + */ + default Optional getIntentAction() { + return Optional.ofNullable((String) getCapability(INTENT_ACTION_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsIntentCategoryOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsIntentCategoryOption.java new file mode 100644 index 000000000..287ac09d4 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsIntentCategoryOption.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.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; + +public interface SupportsIntentCategoryOption> extends + Capabilities, CanSetCapability { + String INTENT_CATEGORY_OPTION = "intentCategory"; + + /** + * Set an optional intent category to be applied when + * starting the given appActivity by Activity Manager. + * + * @param intentCategory Intent category class name. + * @return self instance for chaining. + */ + default T setIntentCategory(String intentCategory) { + return amend(INTENT_CATEGORY_OPTION, intentCategory); + } + + /** + * Get intent category to be applied when + * starting the given appActivity by Activity Manager. + * + * @return Intent category class name. + */ + default Optional getIntentCategory() { + return Optional.ofNullable((String) getCapability(INTENT_CATEGORY_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsIntentFlagsOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsIntentFlagsOption.java new file mode 100644 index 000000000..6c9ed08a8 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsIntentFlagsOption.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.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; + +public interface SupportsIntentFlagsOption> extends + Capabilities, CanSetCapability { + String INTENT_FLAGS_OPTION = "intentFlags"; + + /** + * Set an optional intent flags to be applied when + * starting the given appActivity by Activity Manager. + * + * @param intentFlags Intent flags hexadecimal string. + * @return self instance for chaining. + */ + default T setIntentFlags(String intentFlags) { + return amend(INTENT_FLAGS_OPTION, intentFlags); + } + + /** + * Get intent flags to be applied when + * starting the given appActivity by Activity Manager. + * + * @return Intent flags string. + */ + default Optional getIntentFlags() { + return Optional.ofNullable((String) getCapability(INTENT_FLAGS_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsOptionalIntentArgumentsOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsOptionalIntentArgumentsOption.java new file mode 100644 index 000000000..da5d5a3c7 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsOptionalIntentArgumentsOption.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.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; + +public interface SupportsOptionalIntentArgumentsOption> extends + Capabilities, CanSetCapability { + String OPTIONAL_INTENT_ARGUMENTS_OPTION = "optionalIntentArguments"; + + /** + * Set an optional intent arguments to be applied when + * starting the given appActivity by Activity Manager. + * + * @param arguments Intent arguments string. + * @return self instance for chaining. + */ + default T setOptionalIntentArguments(String arguments) { + return amend(OPTIONAL_INTENT_ARGUMENTS_OPTION, arguments); + } + + /** + * Get intent arguments to be applied when + * starting the given appActivity by Activity Manager. + * + * @return Intent arguments string. + */ + default Optional getOptionalIntentArguments() { + return Optional.ofNullable((String) getCapability(OPTIONAL_INTENT_ARGUMENTS_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsRemoteAppsCacheLimitOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsRemoteAppsCacheLimitOption.java new file mode 100644 index 000000000..e44e8fcf4 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsRemoteAppsCacheLimitOption.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.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.toInteger; + +public interface SupportsRemoteAppsCacheLimitOption> extends + Capabilities, CanSetCapability { + String REMOTE_APPS_CACHE_LIMIT_OPTION = "remoteAppsCacheLimit"; + + /** + * Sets the maximum amount of application packages to be cached on the device under test. + * This is needed for devices that don't support streamed installs (Android 7 and below), + * because ADB must push app packages to the device first in order to install them, + * which takes some time. Setting this capability to zero disables apps caching. + * 10 by default. + * + * @param limit The maximum amount of cached apps. + * @return self instance for chaining. + */ + default T setRemoteAppsCacheLimit(int limit) { + return amend(REMOTE_APPS_CACHE_LIMIT_OPTION, limit); + } + + /** + * Get the maximum amount of apps that could be cached on the remote device. + * + * @return The maximum amount of cached apps. + */ + default Optional getRemoteAppsCacheLimit() { + return Optional.ofNullable(toInteger(getCapability(REMOTE_APPS_CACHE_LIMIT_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/app/SupportsUninstallOtherPackagesOption.java b/src/main/java/io/appium/java_client/android/options/app/SupportsUninstallOtherPackagesOption.java new file mode 100644 index 000000000..fb1402d79 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/app/SupportsUninstallOtherPackagesOption.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.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; + +public interface SupportsUninstallOtherPackagesOption> extends + Capabilities, CanSetCapability { + String UNINSTALL_OTHER_PACKAGES_OPTION = "uninstallOtherPackages"; + + /** + * Allows to set one or more comma-separated package + * identifiers to be uninstalled from the device before a test starts. + * + * @param packages one or more comma-separated package identifiers to uninstall. + * @return self instance for chaining. + */ + default T setUninstallOtherPackages(String packages) { + return amend(UNINSTALL_OTHER_PACKAGES_OPTION, packages); + } + + /** + * Get identifiers of packages to be uninstalled from the device before a test starts. + * + * @return Comma-separated package identifiers. + */ + default Optional getUninstallOtherPackages() { + return Optional.ofNullable((String) getCapability(UNINSTALL_OTHER_PACKAGES_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsDisableWindowAnimationOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsDisableWindowAnimationOption.java new file mode 100644 index 000000000..c8acbaac9 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsDisableWindowAnimationOption.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.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; + +public interface SupportsDisableWindowAnimationOption> extends + Capabilities, CanSetCapability { + String DISABLE_WINDOWS_ANIMATION_OPTION = "disableWindowAnimation"; + + /** + * Disables window animations when starting the instrumentation process. + * + * @return self instance for chaining. + */ + default T disableWindowAnimation() { + return amend(DISABLE_WINDOWS_ANIMATION_OPTION, true); + } + + /** + * Set whether to disable window animations when starting the instrumentation process. + * false by default + * + * @param value True to disable window animations. + * @return self instance for chaining. + */ + default T setDisableWindowAnimation(boolean value) { + return amend(DISABLE_WINDOWS_ANIMATION_OPTION, value); + } + + /** + * Get whether window animations when starting the instrumentation process + * are disabled. + * + * @return True or false. + */ + default Optional doesDisableWindowAnimation() { + return Optional.ofNullable(toSafeBoolean(getCapability(DISABLE_WINDOWS_ANIMATION_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsSkipDeviceInitializationOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsSkipDeviceInitializationOption.java new file mode 100644 index 000000000..2b42327bb --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsSkipDeviceInitializationOption.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.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; + +public interface SupportsSkipDeviceInitializationOption> extends + Capabilities, CanSetCapability { + String SKIP_DEVICE_INITIALIZATION_OPTION = "skipDeviceInitialization"; + + /** + * Disables initial device startup checks by the server. + * + * @return self instance for chaining. + */ + default T skipDeviceInitialization() { + return amend(SKIP_DEVICE_INITIALIZATION_OPTION, true); + } + + /** + * If set to true then device startup checks (whether it is ready and whether + * Settings app is installed) will be canceled on session creation. + * Could speed up the session creation if you know what you are doing. false by default + * + * @param value True to skip device initialization. + * @return self instance for chaining. + */ + default T setSkipDeviceInitialization(boolean value) { + return amend(SKIP_DEVICE_INITIALIZATION_OPTION, value); + } + + /** + * Get whether initial device startup checks by the server are disabled. + * + * @return True or false. + */ + default Optional doesSkipDeviceInitialization() { + return Optional.ofNullable(toSafeBoolean(getCapability(SKIP_DEVICE_INITIALIZATION_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsSkipServerInstallationOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsSkipServerInstallationOption.java new file mode 100644 index 000000000..088f040fc --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsSkipServerInstallationOption.java @@ -0,0 +1,71 @@ +/* + * 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; + +public interface SupportsSkipServerInstallationOption> extends + Capabilities, CanSetCapability { + String SKIP_SERVER_INSTALLATION_OPTION = "skipServerInstallation"; + + /** + * Enables skipping of the UiAutomator2 Server component installation + * on the device under test and all the related checks. + * This could help to speed up the session startup if you know for sure the + * correct server version is installed on the device. + * In case the server is not installed or an incorrect version of it is installed + * then you may get an unexpected error later. + * + * @return self instance for chaining. + */ + default T skipServerInstallation() { + return amend(SKIP_SERVER_INSTALLATION_OPTION, true); + } + + /** + * Set whether to skip the UiAutomator2 Server component installation + * on the device under test and all the related checks. + * This could help to speed up the session startup if you know for sure the + * correct server version is installed on the device. + * In case the server is not installed or an incorrect version of it is installed + * then you may get an unexpected error later. + * + * @param value True to skip the server installation. + * @return self instance for chaining. + */ + default T setSkipServerInstallation(boolean value) { + return amend(SKIP_SERVER_INSTALLATION_OPTION, value); + } + + /** + * Get whether to skip the UiAutomator2 Server component installation + * on the device under test and all the related checks. + * + * @return True or false. + */ + default Optional doesSkipServerInstallation() { + return Optional.ofNullable( + toSafeBoolean(getCapability(SKIP_SERVER_INSTALLATION_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsSystemPortOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsSystemPortOption.java new file mode 100644 index 000000000..cf638ff9f --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsSystemPortOption.java @@ -0,0 +1,52 @@ +/* + * 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.toInteger; + +public interface SupportsSystemPortOption> extends + Capabilities, CanSetCapability { + String SYSTEM_PORT_OPTION = "systemPort"; + + /** + * The number of the port the UiAutomator2 server is listening on. + * By default, the first free port from 8200..8299 range is selected. + * It is recommended to set this value if you are running parallel + * tests on the same machine. + * + * @param port port number in range 0..65535 + * @return self instance for chaining. + */ + default T setSystemPort(int port) { + return amend(SYSTEM_PORT_OPTION, port); + } + + /** + * Get the system port value. + * + * @return System port value + */ + default Optional getSystemPort() { + return Optional.ofNullable(toInteger(getCapability(SYSTEM_PORT_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerInstallTimeoutOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerInstallTimeoutOption.java new file mode 100644 index 000000000..dac3b3b38 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerInstallTimeoutOption.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.server; + +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 SupportsUiautomator2ServerInstallTimeoutOption> extends + Capabilities, CanSetCapability { + String UIAUTOMATOR2_SERVER_INSTALL_TIMEOUT_OPTION = "uiautomator2ServerInstallTimeout"; + + /** + * Set the maximum timeout to wait util UiAutomator2Server is installed on the device. + * 20000 ms by default + * + * @param timeout Timeout value. + * @return self instance for chaining. + */ + default T setUiautomator2ServerInstallTimeout(Duration timeout) { + return amend(UIAUTOMATOR2_SERVER_INSTALL_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the maximum timeout to wait until UiAutomator2Server is installed on the device. + * + * @return The timeout value. + */ + default Optional getUiautomator2ServerInstallTimeout() { + return Optional.ofNullable( + toDuration(getCapability(UIAUTOMATOR2_SERVER_INSTALL_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerLaunchTimeoutOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerLaunchTimeoutOption.java new file mode 100644 index 000000000..ea12f0d09 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerLaunchTimeoutOption.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.server; + +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 SupportsUiautomator2ServerLaunchTimeoutOption> extends + Capabilities, CanSetCapability { + String UIAUTOMATOR2_SERVER_LAUNCH_TIMEOUT_OPTION = "uiautomator2ServerLaunchTimeout"; + + /** + * Set the maximum timeout to wait util UiAutomator2Server is listening on + * the device. 30000 ms by default + * + * @param timeout Timeout value. + * @return self instance for chaining. + */ + default T setUiautomator2ServerLaunchTimeout(Duration timeout) { + return amend(UIAUTOMATOR2_SERVER_LAUNCH_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the maximum timeout to wait until UiAutomator2Server is listening on the device. + * + * @return The timeout value. + */ + default Optional getUiautomator2ServerLaunchTimeout() { + return Optional.ofNullable( + toDuration(getCapability(UIAUTOMATOR2_SERVER_LAUNCH_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerReadTimeoutOption.java b/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerReadTimeoutOption.java new file mode 100644 index 000000000..699b73c48 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/options/server/SupportsUiautomator2ServerReadTimeoutOption.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.server; + +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 SupportsUiautomator2ServerReadTimeoutOption> extends + Capabilities, CanSetCapability { + String UIAUTOMATOR2_SERVER_READ_TIMEOUT_OPTION = "uiautomator2ServerReadTimeout"; + + /** + * Set the maximum timeout to wait for a HTTP response from UiAutomator2Server. + * Only values greater than zero are accepted. If the given value is too low + * then expect driver commands to fail with timeout of Xms exceeded error. + * 240000 ms by default + * + * @param timeout Timeout value. + * @return self instance for chaining. + */ + default T setUiautomator2ServerReadTimeout(Duration timeout) { + return amend(UIAUTOMATOR2_SERVER_READ_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the maximum timeout to wait for a HTTP response from UiAutomator2Server. + * + * @return The timeout value. + */ + default Optional getUiautomator2ServerReadTimeout() { + return Optional.ofNullable( + toDuration(getCapability(UIAUTOMATOR2_SERVER_READ_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/internal/CapabilityHelpers.java b/src/main/java/io/appium/java_client/internal/CapabilityHelpers.java index b97da189c..106b96c59 100644 --- a/src/main/java/io/appium/java_client/internal/CapabilityHelpers.java +++ b/src/main/java/io/appium/java_client/internal/CapabilityHelpers.java @@ -19,8 +19,10 @@ import org.openqa.selenium.Capabilities; import javax.annotation.Nullable; +import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; public class CapabilityHelpers { public static final String APPIUM_PREFIX = "appium:"; @@ -46,7 +48,7 @@ public static T getCapability(Capabilities caps, String name, Class expec if (caps.getCapability(capName) == null) { continue; } - + if (expectedType == String.class) { return expectedType.cast(String.valueOf(caps.getCapability(capName))); } @@ -56,4 +58,83 @@ public static T getCapability(Capabilities caps, String name, Class expec } return null; } + + /** + * Converts generic capability value to boolean without + * throwing exceptions. + * + * @param value The capability value. + * @return null is the passed value is null otherwise the converted value. + */ + @Nullable + public static Boolean toSafeBoolean(Object value) { + return value == null ? null : Boolean.parseBoolean(String.valueOf(value)); + } + + /** + * Converts generic capability value to integer. + * + * @param value The capability value. + * @throws NumberFormatException If the given value cannot be parsed to a valid integer. + * @return null is the passed value is null otherwise the converted value. + */ + @Nullable + public static Integer toInteger(Object value) { + if (value == null) { + return null; + } else if (value instanceof Number) { + return ((Number) value).intValue(); + } else { + return Integer.parseInt(String.valueOf(value)); + } + } + + /** + * Converts generic capability value to long without + * throwing exceptions. + * + * @param value The capability value. + * @throws NumberFormatException If the given value cannot be parsed to a valid long. + * @return null is the passed value is null otherwise the converted value. + */ + @Nullable + public static Long toLong(Object value) { + if (value == null) { + return null; + } else if (value instanceof Number) { + return ((Number) value).longValue(); + } else { + return Long.parseLong(String.valueOf(value)); + } + } + + /** + * Converts generic capability value to duration without + * throwing exceptions. The value is assumed to be + * measured in milliseconds. + * + * @param value The capability value. + * @throws NumberFormatException If the given value cannot be parsed to a valid number. + * @return null is the passed value is null otherwise the converted value. + */ + @Nullable + public static Duration toDuration(Object value) { + return toDuration(value, Duration::ofMillis); + } + + /** + * Converts generic capability value to duration without + * throwing exceptions. + * + * @param value The capability value. + * @param converter Converts the numeric value to a Duration instance. + * @throws NumberFormatException If the given value cannot be parsed to a valid number. + * @return null is the passed value is null otherwise the converted value. + */ + @Nullable + public static Duration toDuration(Object value, + Function converter) { + Long v = toLong(value); + return v == null ? null : converter.apply(v); + } } diff --git a/src/main/java/io/appium/java_client/remote/MobileOptions.java b/src/main/java/io/appium/java_client/remote/MobileOptions.java index fad8d5ad1..98bd098b7 100644 --- a/src/main/java/io/appium/java_client/remote/MobileOptions.java +++ b/src/main/java/io/appium/java_client/remote/MobileOptions.java @@ -16,18 +16,13 @@ package io.appium.java_client.remote; -import io.appium.java_client.remote.options.BaseOptions; -import io.appium.java_client.remote.options.SupportsAppOption; -import io.appium.java_client.remote.options.SupportsAutoWebViewOption; -import io.appium.java_client.remote.options.SupportsClearSystemFilesOption; -import io.appium.java_client.remote.options.SupportsDeviceNameOption; -import io.appium.java_client.remote.options.SupportsEnablePerformanceLoggingOption; -import io.appium.java_client.remote.options.SupportsLanguageOption; -import io.appium.java_client.remote.options.SupportsLocaleOption; -import io.appium.java_client.remote.options.SupportsOrientationOption; -import io.appium.java_client.remote.options.SupportsOtherAppsOption; -import io.appium.java_client.remote.options.SupportsUdidOption; import org.openqa.selenium.Capabilities; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.ScreenOrientation; +import org.openqa.selenium.remote.CapabilityType; + +import java.net.URL; +import java.time.Duration; /** * Use the specific options class for your driver, @@ -36,12 +31,7 @@ * @param The child class for a proper chaining. */ @Deprecated -public class MobileOptions> extends BaseOptions - implements SupportsAppOption, SupportsAutoWebViewOption, - SupportsClearSystemFilesOption, SupportsDeviceNameOption, - SupportsEnablePerformanceLoggingOption, SupportsLanguageOption, - SupportsLocaleOption, SupportsOrientationOption, SupportsOtherAppsOption, - SupportsUdidOption { +public class MobileOptions> extends MutableCapabilities { /** * Creates new instance with no preset capabilities. @@ -57,4 +47,466 @@ public MobileOptions() { public MobileOptions(Capabilities source) { super(source); } + + /** + * Set the kind of mobile device or emulator to use. + * + * @param platform the kind of mobile device or emulator to use. + * @return this MobileOptions, for chaining. + * @see org.openqa.selenium.remote.CapabilityType#PLATFORM_NAME + */ + public T setPlatformName(String platform) { + return amend(CapabilityType.PLATFORM_NAME, platform); + } + + /** + * Set the absolute local path for the location of the App. + * The or remote http URL to a {@code .ipa} file (IOS), + * + * @param path is a String representing the location of the App + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#APP + */ + public T setApp(String path) { + return amend(MobileCapabilityType.APP, path); + } + + /** + * Set the remote http URL for the location of the App. + * + * @param url is the URL representing the location of the App + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#APP + */ + public T setApp(URL url) { + return setApp(url.toString()); + } + + /** + * Get the app location. + * + * @return String representing app location + * @see MobileCapabilityType#APP + */ + public String getApp() { + return (String) getCapability(MobileCapabilityType.APP); + } + + /** + * Set the automation engine to use. + * + * @param name is the name of the automation engine + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#AUTOMATION_NAME + */ + public T setAutomationName(String name) { + return amend(MobileCapabilityType.AUTOMATION_NAME, name); + } + + /** + * Get the automation engine to use. + * + * @return String representing the name of the automation engine + * @see MobileCapabilityType#AUTOMATION_NAME + */ + public String getAutomationName() { + return (String) getCapability(MobileCapabilityType.AUTOMATION_NAME); + } + + /** + * Set the app to move directly into Webview context. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#AUTO_WEBVIEW + */ + public T setAutoWebview() { + return setAutoWebview(true); + } + + /** + * Set whether the app moves directly into Webview context. + * + * @param bool is whether the app moves directly into Webview context. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#AUTO_WEBVIEW + */ + public T setAutoWebview(boolean bool) { + return amend(MobileCapabilityType.AUTO_WEBVIEW, bool); + } + + /** + * Get whether the app moves directly into Webview context. + * + * @return true if app moves directly into Webview context. + * @see MobileCapabilityType#AUTO_WEBVIEW + */ + public boolean doesAutoWebview() { + return (boolean) getCapability(MobileCapabilityType.AUTO_WEBVIEW); + } + + /** + * Set the app to delete any generated files at the end of a session. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#CLEAR_SYSTEM_FILES + */ + public T setClearSystemFiles() { + return setClearSystemFiles(true); + } + + /** + * Set whether the app deletes generated files at the end of a session. + * + * @param bool is whether the app deletes generated files at the end of a session. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#CLEAR_SYSTEM_FILES + */ + public T setClearSystemFiles(boolean bool) { + return amend(MobileCapabilityType.CLEAR_SYSTEM_FILES, bool); + } + + /** + * Get whether the app deletes generated files at the end of a session. + * + * @return true if the app deletes generated files at the end of a session. + * @see MobileCapabilityType#CLEAR_SYSTEM_FILES + */ + public boolean doesClearSystemFiles() { + return (boolean) getCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES); + } + + /** + * Set the name of the device. + * + * @param deviceName is the name of the device. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#DEVICE_NAME + */ + public T setDeviceName(String deviceName) { + return amend(MobileCapabilityType.DEVICE_NAME, deviceName); + } + + /** + * Get the name of the device. + * + * @return String representing the name of the device. + * @see MobileCapabilityType#DEVICE_NAME + */ + public String getDeviceName() { + return (String) getCapability(MobileCapabilityType.DEVICE_NAME); + } + + /** + * Set the app to enable performance logging. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING + */ + public T setEnablePerformanceLogging() { + return setEnablePerformanceLogging(true); + } + + /** + * Set whether the app logs performance. + * + * @param bool is whether the app logs performance. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING + */ + public T setEnablePerformanceLogging(boolean bool) { + return amend(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING, bool); + } + + /** + * Get the app logs performance. + * + * @return true if the app logs performance. + * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING + */ + public boolean isEnablePerformanceLogging() { + return (boolean) getCapability(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING); + } + + /** + * Set the app to report the timings for various Appium-internal events. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#EVENT_TIMINGS + */ + public T setEventTimings() { + return setEventTimings(true); + } + + /** + * Set whether the app reports the timings for various Appium-internal events. + * + * @param bool is whether the app enables event timings. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#EVENT_TIMINGS + */ + public T setEventTimings(boolean bool) { + return amend(MobileCapabilityType.EVENT_TIMINGS, bool); + } + + /** + * Get whether the app reports the timings for various Appium-internal events. + * + * @return true if the app reports event timings. + * @see MobileCapabilityType#EVENT_TIMINGS + */ + public boolean doesEventTimings() { + return (boolean) getCapability(MobileCapabilityType.EVENT_TIMINGS); + } + + /** + * Set the app to do a full reset. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#FULL_RESET + */ + public T setFullReset() { + return setFullReset(true); + } + + /** + * Set whether the app does a full reset. + * + * @param bool is whether the app does a full reset. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#FULL_RESET + */ + public T setFullReset(boolean bool) { + return amend(MobileCapabilityType.FULL_RESET, bool); + } + + /** + * Get whether the app does a full reset. + * + * @return true if the app does a full reset. + * @see MobileCapabilityType#FULL_RESET + */ + public boolean doesFullReset() { + return (boolean) getCapability(MobileCapabilityType.FULL_RESET); + } + + /** + * Set language abbreviation for use in session. + * + * @param language is the language abbreviation. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#LANGUAGE + */ + public T setLanguage(String language) { + return amend(MobileCapabilityType.LANGUAGE, language); + } + + /** + * Get language abbreviation for use in session. + * + * @return String representing the language abbreviation. + * @see MobileCapabilityType#LANGUAGE + */ + public String getLanguage() { + return (String) getCapability(MobileCapabilityType.LANGUAGE); + } + + /** + * Set locale abbreviation for use in session. + * + * @param locale is the locale abbreviation. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#LOCALE + */ + public T setLocale(String locale) { + return amend(MobileCapabilityType.LOCALE, locale); + } + + /** + * Get locale abbreviation for use in session. + * + * @return String representing the locale abbreviation. + * @see MobileCapabilityType#LOCALE + */ + public String getLocale() { + return (String) getCapability(MobileCapabilityType.LOCALE); + } + + /** + * Set the timeout for new commands. + * + * @param duration is the allowed time before seeing a new command. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT + */ + public T setNewCommandTimeout(Duration duration) { + return amend(MobileCapabilityType.NEW_COMMAND_TIMEOUT, duration.getSeconds()); + } + + /** + * Get the timeout for new commands. + * + * @return allowed time before seeing a new command. + * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT + */ + public Duration getNewCommandTimeout() { + Object duration = getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT); + return Duration.ofSeconds(Long.parseLong("" + duration)); + } + + /** + * Set the app not to do a reset. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#NO_RESET + */ + public T setNoReset() { + return setNoReset(true); + } + + /** + * Set whether the app does not do a reset. + * + * @param bool is whether the app does not do a reset. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#NO_RESET + */ + public T setNoReset(boolean bool) { + return amend(MobileCapabilityType.NO_RESET, bool); + } + + /** + * Get whether the app does not do a reset. + * + * @return true if the app does not do a reset. + * @see MobileCapabilityType#NO_RESET + */ + public boolean doesNoReset() { + return (boolean) getCapability(MobileCapabilityType.NO_RESET); + } + + /** + * Set the orientation of the screen. + * + * @param orientation is the screen orientation. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#ORIENTATION + */ + public T setOrientation(ScreenOrientation orientation) { + return amend(MobileCapabilityType.ORIENTATION, orientation); + } + + /** + * Get the orientation of the screen. + * + * @return ScreenOrientation of the app. + * @see MobileCapabilityType#ORIENTATION + */ + public ScreenOrientation getOrientation() { + return (ScreenOrientation) getCapability(MobileCapabilityType.ORIENTATION); + } + + /** + * Set the location of the app(s) to install before running a test. + * + * @param apps is the apps to install. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#OTHER_APPS + */ + public T setOtherApps(String apps) { + return amend(MobileCapabilityType.OTHER_APPS, apps); + } + + /** + * Get the list of apps to install before running a test. + * + * @return String of apps to install. + * @see MobileCapabilityType#OTHER_APPS + */ + public String getOtherApps() { + return (String) getCapability(MobileCapabilityType.OTHER_APPS); + } + + /** + * Set the version of the platform. + * + * @param version is the platform version. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#PLATFORM_VERSION + */ + public T setPlatformVersion(String version) { + return amend(MobileCapabilityType.PLATFORM_VERSION, version); + } + + /** + * Get the version of the platform. + * + * @return String representing the platform version. + * @see MobileCapabilityType#PLATFORM_VERSION + */ + public String getPlatformVersion() { + return (String) getCapability(MobileCapabilityType.PLATFORM_VERSION); + } + + /** + * Set the app to print page source when a find operation fails. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE + */ + public T setPrintPageSourceOnFindFailure() { + return setPrintPageSourceOnFindFailure(true); + } + + /** + * Set whether the app to print page source when a find operation fails. + * + * @param bool is whether to print page source. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE + */ + public T setPrintPageSourceOnFindFailure(boolean bool) { + return amend(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE, bool); + } + + /** + * Get whether the app to print page source when a find operation fails. + * + * @return true if app prints page source. + * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE + */ + public boolean doesPrintPageSourceOnFindFailure() { + return (boolean) getCapability(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE); + } + + /** + * Set the id of the device. + * + * @param id is the unique device identifier. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#UDID + */ + public T setUdid(String id) { + return amend(MobileCapabilityType.UDID, id); + } + + /** + * Get the id of the device. + * + * @return String representing the unique device identifier. + * @see MobileCapabilityType#UDID + */ + public String getUdid() { + return (String) getCapability(MobileCapabilityType.UDID); + } + + @Override + public T merge(Capabilities extraCapabilities) { + super.merge(extraCapabilities); + return (T) this; + } + + protected T amend(String optionName, Object value) { + setCapability(optionName, value); + return (T) this; + } } diff --git a/src/main/java/io/appium/java_client/remote/options/BaseOptions.java b/src/main/java/io/appium/java_client/remote/options/BaseOptions.java index cdfb8f168..ff575989f 100644 --- a/src/main/java/io/appium/java_client/remote/options/BaseOptions.java +++ b/src/main/java/io/appium/java_client/remote/options/BaseOptions.java @@ -16,13 +16,13 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.internal.Require; import org.openqa.selenium.remote.AcceptedW3CCapabilityKeys; import org.openqa.selenium.remote.CapabilityType; -import java.time.Duration; +import javax.annotation.Nullable; import java.util.Map; import java.util.stream.Collectors; @@ -35,12 +35,13 @@ * * @param The child class for a proper chaining. */ -@SuppressWarnings("unused") +@SuppressWarnings({"unused", "UnusedReturnValue"}) public class BaseOptions> extends MutableCapabilities - implements CanSetCapability { - private static final AcceptedW3CCapabilityKeys W3C_KEY_PATTERNS = - new AcceptedW3CCapabilityKeys(); - + implements CanSetCapability, SupportsAutomationNameOption, + SupportsEventTimingsOption, SupportsPrintPageSourceOnFindFailureOption, + SupportsNoResetOption, SupportsFullResetOption, SupportsNewCommandTimeoutOption, + SupportsPlatformVersionOption { + private static final AcceptedW3CCapabilityKeys W3C_KEY_PATTERNS = new AcceptedW3CCapabilityKeys(); /** * Creates new instance with no preset capabilities. @@ -68,194 +69,6 @@ public T setPlatformName(String platform) { return amend(CapabilityType.PLATFORM_NAME, platform); } - /** - * Set the automation engine to use. - * - * @param name is the name of the automation engine - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#AUTOMATION_NAME - */ - public T setAutomationName(String name) { - return amend(MobileCapabilityType.AUTOMATION_NAME, name); - } - - /** - * Get the automation engine to use. - * - * @return String representing the name of the automation engine - * @see MobileCapabilityType#AUTOMATION_NAME - */ - public String getAutomationName() { - return (String) getCapability(MobileCapabilityType.AUTOMATION_NAME); - } - - /** - * Set the app to report the timings for various Appium-internal events. - * - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#EVENT_TIMINGS - */ - public T setEventTimings() { - return setEventTimings(true); - } - - /** - * Set whether the app reports the timings for various Appium-internal events. - * - * @param bool is whether the app enables event timings. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#EVENT_TIMINGS - */ - public T setEventTimings(boolean bool) { - return amend(MobileCapabilityType.EVENT_TIMINGS, bool); - } - - /** - * Get whether the app reports the timings for various Appium-internal events. - * - * @return true if the app reports event timings. - * @see MobileCapabilityType#EVENT_TIMINGS - */ - public boolean doesEventTimings() { - return (boolean) getCapability(MobileCapabilityType.EVENT_TIMINGS); - } - - /** - * Set the app to do a full reset. - * - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#FULL_RESET - */ - public T setFullReset() { - return setFullReset(true); - } - - /** - * Set whether the app does a full reset. - * - * @param bool is whether the app does a full reset. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#FULL_RESET - */ - public T setFullReset(boolean bool) { - return amend(MobileCapabilityType.FULL_RESET, bool); - } - - /** - * Get whether the app does a full reset. - * - * @return true if the app does a full reset. - * @see MobileCapabilityType#FULL_RESET - */ - public boolean doesFullReset() { - return (boolean) getCapability(MobileCapabilityType.FULL_RESET); - } - - /** - * Set the timeout for new commands. - * - * @param duration is the allowed time before seeing a new command. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT - */ - public T setNewCommandTimeout(Duration duration) { - return amend(MobileCapabilityType.NEW_COMMAND_TIMEOUT, duration.getSeconds()); - } - - /** - * Get the timeout for new commands. - * - * @return allowed time before seeing a new command. - * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT - */ - public Duration getNewCommandTimeout() { - Object duration = getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT); - return Duration.ofSeconds(Long.parseLong("" + duration)); - } - - /** - * Set the app not to do a reset. - * - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#NO_RESET - */ - public T setNoReset() { - return setNoReset(true); - } - - /** - * Set whether the app does not do a reset. - * - * @param bool is whether the app does not do a reset. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#NO_RESET - */ - public T setNoReset(boolean bool) { - return amend(MobileCapabilityType.NO_RESET, bool); - } - - /** - * Get whether the app does not do a reset. - * - * @return true if the app does not do a reset. - * @see MobileCapabilityType#NO_RESET - */ - public boolean doesNoReset() { - return (boolean) getCapability(MobileCapabilityType.NO_RESET); - } - - /** - * Set the version of the platform. - * - * @param version is the platform version. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#PLATFORM_VERSION - */ - public T setPlatformVersion(String version) { - return amend(MobileCapabilityType.PLATFORM_VERSION, version); - } - - /** - * Get the version of the platform. - * - * @return String representing the platform version. - * @see MobileCapabilityType#PLATFORM_VERSION - */ - public String getPlatformVersion() { - return (String) getCapability(MobileCapabilityType.PLATFORM_VERSION); - } - - /** - * Set the app to print page source when a find operation fails. - * - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE - */ - public T setPrintPageSourceOnFindFailure() { - return setPrintPageSourceOnFindFailure(true); - } - - /** - * Set whether the app to print page source when a find operation fails. - * - * @param bool is whether to print page source. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE - */ - public T setPrintPageSourceOnFindFailure(boolean bool) { - return amend(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE, bool); - } - - /** - * Get whether the app to print page source when a find operation fails. - * - * @return true if app prints page source. - * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE - */ - public boolean doesPrintPageSourceOnFindFailure() { - return (boolean) getCapability(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE); - } - @Override public Map asMap() { return unmodifiableMap(super.asMap().entrySet().stream() @@ -270,4 +83,20 @@ public T merge(Capabilities extraCapabilities) { //noinspection unchecked return (T) this; } -} + + @Override + public void setCapability(String key, @Nullable Object value) { + Require.nonNull("Capability name", key); + super.setCapability(W3C_KEY_PATTERNS.test(key) ? key : APPIUM_PREFIX + key, value); + } + + @Override + @Nullable + public Object getCapability(String capabilityName) { + Object value = super.getCapability(capabilityName); + if (value == null) { + value = super.getCapability(APPIUM_PREFIX + capabilityName); + } + return value; + } +} \ No newline at end of file diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsAppOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsAppOption.java index 8e112a32f..043904fde 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsAppOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsAppOption.java @@ -16,32 +16,32 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; import java.net.URL; +import java.util.Optional; public interface SupportsAppOption> extends Capabilities, CanSetCapability { + String APP_OPTION = "app"; /** * Set the absolute local path for the location of the App. - * The or remote http URL to a {@code .ipa} file (IOS), + * The app must be located on the same machine where Appium + * server is running. * * @param path is a String representing the location of the App - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#APP + * @return self instance for chaining. */ default T setApp(String path) { - return amend(MobileCapabilityType.APP, path); + return amend(APP_OPTION, path); } /** * Set the remote http URL for the location of the App. * * @param url is the URL representing the location of the App - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#APP + * @return self instance for chaining. */ default T setApp(URL url) { return setApp(url.toString()); @@ -51,9 +51,8 @@ default T setApp(URL url) { * Get the app location. * * @return String representing app location - * @see MobileCapabilityType#APP */ - default String getApp() { - return (String) getCapability(MobileCapabilityType.APP); + default Optional getApp() { + return Optional.ofNullable((String) getCapability(APP_OPTION)); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsAutoWebViewOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsAutoWebViewOption.java index 8c68c20bf..8a5d7e9fd 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsAutoWebViewOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsAutoWebViewOption.java @@ -16,18 +16,22 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + public interface SupportsAutoWebViewOption> extends Capabilities, CanSetCapability { + String AUTO_WEB_VIEW_OPTION = "autoWebView"; + /** * Set the app to move directly into Webview context. * - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#AUTO_WEBVIEW + * @return self instance for chaining. */ - default T setAutoWebview() { + default T autoWebview() { return setAutoWebview(true); } @@ -35,20 +39,18 @@ default T setAutoWebview() { * Set whether the app moves directly into Webview context. * * @param bool is whether the app moves directly into Webview context. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#AUTO_WEBVIEW + * @return self instance for chaining. */ default T setAutoWebview(boolean bool) { - return amend(MobileCapabilityType.AUTO_WEBVIEW, bool); + return amend(AUTO_WEB_VIEW_OPTION, bool); } /** * Get whether the app moves directly into Webview context. * * @return true if app moves directly into Webview context. - * @see MobileCapabilityType#AUTO_WEBVIEW */ - default boolean doesAutoWebview() { - return (boolean) getCapability(MobileCapabilityType.AUTO_WEBVIEW); + default Optional doesAutoWebview() { + return Optional.ofNullable(toSafeBoolean(getCapability(AUTO_WEB_VIEW_OPTION))); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsAutomationNameOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsAutomationNameOption.java new file mode 100644 index 000000000..2fdb5870d --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsAutomationNameOption.java @@ -0,0 +1,45 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +public interface SupportsAutomationNameOption> extends + Capabilities, CanSetCapability { + String AUTOMATION_NAME_OPTION = "automationName"; + + /** + * Set the automation driver to use. + * + * @param automationName One of supported automation names. + * @return self instance for chaining. + */ + default T setAutomationName(String automationName) { + return amend(AUTOMATION_NAME_OPTION, automationName); + } + + /** + * Get the automation driver to use. + * + * @return String representing the name of the automation engine + */ + default Optional getAutomationName() { + return Optional.ofNullable((String) getCapability(AUTOMATION_NAME_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsClearSystemFilesOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsClearSystemFilesOption.java index 162956fc1..0d652a1da 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsClearSystemFilesOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsClearSystemFilesOption.java @@ -16,19 +16,22 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + public interface SupportsClearSystemFilesOption> extends Capabilities, CanSetCapability { + String CLEAR_SYSTEM_FILES_OPTION = "clearSystemFiles"; /** * Set the app to delete any generated files at the end of a session. * * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#CLEAR_SYSTEM_FILES */ - default T setClearSystemFiles() { + default T clearSystemFiles() { return setClearSystemFiles(true); } @@ -37,19 +40,17 @@ default T setClearSystemFiles() { * * @param bool is whether the app deletes generated files at the end of a session. * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#CLEAR_SYSTEM_FILES */ default T setClearSystemFiles(boolean bool) { - return amend(MobileCapabilityType.CLEAR_SYSTEM_FILES, bool); + return amend(CLEAR_SYSTEM_FILES_OPTION, bool); } /** * Get whether the app deletes generated files at the end of a session. * * @return true if the app deletes generated files at the end of a session. - * @see MobileCapabilityType#CLEAR_SYSTEM_FILES */ - default boolean doesClearSystemFiles() { - return (boolean) getCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES); + default Optional doesClearSystemFiles() { + return Optional.ofNullable(toSafeBoolean(getCapability(CLEAR_SYSTEM_FILES_OPTION))); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsDeviceNameOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsDeviceNameOption.java index 91f1a8c75..729741bbc 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsDeviceNameOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsDeviceNameOption.java @@ -16,29 +16,30 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + public interface SupportsDeviceNameOption> extends Capabilities, CanSetCapability { + String DEVICE_NAME_OPTION = "deviceName"; + /** * Set the name of the device. * * @param deviceName is the name of the device. * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#DEVICE_NAME */ default T setDeviceName(String deviceName) { - return amend(MobileCapabilityType.DEVICE_NAME, deviceName); + return amend(DEVICE_NAME_OPTION, deviceName); } /** * Get the name of the device. * * @return String representing the name of the device. - * @see MobileCapabilityType#DEVICE_NAME */ - default String getDeviceName() { - return (String) getCapability(MobileCapabilityType.DEVICE_NAME); + default Optional getDeviceName() { + return Optional.ofNullable((String) getCapability(DEVICE_NAME_OPTION)); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsEnablePerformanceLoggingOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsEnablePerformanceLoggingOption.java index 82ff44573..cf3601925 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsEnablePerformanceLoggingOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsEnablePerformanceLoggingOption.java @@ -16,19 +16,22 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + public interface SupportsEnablePerformanceLoggingOption> extends Capabilities, CanSetCapability { + String ENABLE_PERFORMANCE_LOGGING_OPTION = "enablePerformanceLogging"; /** * Set the app to enable performance logging. * - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING + * @return self instance for chaining. */ - default T setEnablePerformanceLogging() { + default T enablePerformanceLogging() { return setEnablePerformanceLogging(true); } @@ -36,20 +39,18 @@ default T setEnablePerformanceLogging() { * Set whether the app logs performance. * * @param bool is whether the app logs performance. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING + * @return self instance for chaining. */ default T setEnablePerformanceLogging(boolean bool) { - return amend(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING, bool); + return amend(ENABLE_PERFORMANCE_LOGGING_OPTION, bool); } /** * Get the app logs performance. * * @return true if the app logs performance. - * @see MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING */ - default boolean isEnablePerformanceLogging() { - return (boolean) getCapability(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING); + default Optional isEnablePerformanceLogging() { + return Optional.ofNullable(toSafeBoolean(getCapability(ENABLE_PERFORMANCE_LOGGING_OPTION))); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsEventTimingsOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsEventTimingsOption.java new file mode 100644 index 000000000..3d6bd39e6 --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsEventTimingsOption.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.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsEventTimingsOption> extends + Capabilities, CanSetCapability { + String EVENT_TIMINGS_OPTION = "eventTimings"; + + /** + * Set the app to report the timings for various Appium-internal events. + * + * @return self instance for chaining. + */ + default T setEventTimings() { + return setEventTimings(true); + } + + /** + * Set whether the app reports the timings for various Appium-internal events. + * + * @param bool is whether the app enables event timings. + * @return self instance for chaining. + */ + default T setEventTimings(boolean bool) { + return amend(EVENT_TIMINGS_OPTION, bool); + } + + /** + * Get whether the app reports the timings for various Appium-internal events. + * + * @return true if the app reports event timings. + */ + default Optional doesEventTimings() { + return Optional.ofNullable(toSafeBoolean(getCapability(EVENT_TIMINGS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsFullResetOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsFullResetOption.java new file mode 100644 index 000000000..667bb1f3d --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsFullResetOption.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.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsFullResetOption> extends + Capabilities, CanSetCapability { + String FULL_RESET_OPTION = "fullReset"; + + /** + * Set the app to do a full reset. + * + * @return self instance for chaining. + */ + default T fullReset() { + return setFullReset(true); + } + + /** + * Set whether the app does a full reset. + * + * @param bool is whether the app does a full reset. + * @return self instance for chaining. + */ + default T setFullReset(boolean bool) { + return amend(FULL_RESET_OPTION, bool); + } + + /** + * Get whether the app does a full reset. + * + * @return true if the app does a full reset. + */ + default Optional doesFullReset() { + return Optional.ofNullable(toSafeBoolean(getCapability(FULL_RESET_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsLanguageOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsLanguageOption.java index 12e46838e..8428d6f45 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsLanguageOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsLanguageOption.java @@ -16,30 +16,30 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + public interface SupportsLanguageOption> extends Capabilities, CanSetCapability { + String LANGUAGE_OPTION = "language"; /** * Set language abbreviation for use in session. * * @param language is the language abbreviation. * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#LANGUAGE */ default T setLanguage(String language) { - return amend(MobileCapabilityType.LANGUAGE, language); + return amend(LANGUAGE_OPTION, language); } /** * Get language abbreviation for use in session. * * @return String representing the language abbreviation. - * @see MobileCapabilityType#LANGUAGE */ - default String getLanguage() { - return (String) getCapability(MobileCapabilityType.LANGUAGE); + default Optional getLanguage() { + return Optional.ofNullable((String) getCapability(LANGUAGE_OPTION)); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsLocaleOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsLocaleOption.java index f2f0d26e5..37689be59 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsLocaleOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsLocaleOption.java @@ -16,30 +16,30 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + public interface SupportsLocaleOption> extends Capabilities, CanSetCapability { + String LOCALE_OPTION = "locale"; /** * Set locale abbreviation for use in session. * * @param locale is the locale abbreviation. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#LOCALE + * @return self instance for chaining. */ default T setLocale(String locale) { - return amend(MobileCapabilityType.LOCALE, locale); + return amend(LOCALE_OPTION, locale); } /** * Get locale abbreviation for use in session. * * @return String representing the locale abbreviation. - * @see MobileCapabilityType#LOCALE */ - default String getLocale() { - return (String) getCapability(MobileCapabilityType.LOCALE); + default Optional getLocale() { + return Optional.ofNullable((String) getCapability(LOCALE_OPTION)); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsNewCommandTimeoutOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsNewCommandTimeoutOption.java new file mode 100644 index 000000000..f9358fa95 --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsNewCommandTimeoutOption.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.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.time.Duration; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toDuration; + +public interface SupportsNewCommandTimeoutOption> extends + Capabilities, CanSetCapability { + String NEW_COMMAND_TIMEOUT_OPTION = "newCommandTimeout"; + + /** + * Set the timeout for new commands. + * + * @param duration is the allowed time before seeing a new command. + * @return self instance for chaining. + */ + default T setNewCommandTimeout(Duration duration) { + return amend(NEW_COMMAND_TIMEOUT_OPTION, duration.getSeconds()); + } + + /** + * Get the timeout for new commands. + * + * @return allowed time before seeing a new command. + */ + default Optional getNewCommandTimeout() { + return Optional.ofNullable( + toDuration(getCapability(NEW_COMMAND_TIMEOUT_OPTION), Duration::ofSeconds) + ); + } +} diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsNoResetOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsNoResetOption.java new file mode 100644 index 000000000..9116cac48 --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsNoResetOption.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.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsNoResetOption> extends + Capabilities, CanSetCapability { + String NO_RESET_OPTION = "noReset"; + + /** + * Set the app not to do a reset. + * + * @return self instance for chaining. + */ + default T noReset() { + return setNoReset(true); + } + + /** + * Set whether the app does not do a reset. + * + * @param bool is whether the app does not do a reset. + * @return self instance for chaining. + */ + default T setNoReset(boolean bool) { + return amend(NO_RESET_OPTION, bool); + } + + /** + * Get whether the app does not do a reset. + * + * @return true if the app does not do a reset. + */ + default Optional doesNoReset() { + return Optional.ofNullable(toSafeBoolean(getCapability(NO_RESET_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsOrientationOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsOrientationOption.java index 4bc34bb59..e27acbdcf 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsOrientationOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsOrientationOption.java @@ -16,31 +16,35 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ScreenOrientation; +import java.util.Optional; + public interface SupportsOrientationOption> extends Capabilities, CanSetCapability { + String ORIENTATION_OPTION = "orientation"; /** * Set the orientation of the screen. * * @param orientation is the screen orientation. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#ORIENTATION + * @return self instance for chaining. */ default T setOrientation(ScreenOrientation orientation) { - return amend(MobileCapabilityType.ORIENTATION, orientation); + return amend(ORIENTATION_OPTION, orientation.value()); } /** * Get the orientation of the screen. * * @return ScreenOrientation of the app. - * @see MobileCapabilityType#ORIENTATION */ - default ScreenOrientation getOrientation() { - return (ScreenOrientation) getCapability(MobileCapabilityType.ORIENTATION); + default Optional getOrientation() { + return Optional.ofNullable(getCapability(ORIENTATION_OPTION)) + .map((v) -> v instanceof ScreenOrientation + ? (ScreenOrientation) v + : ScreenOrientation.valueOf((String.valueOf(v)).toUpperCase()) + ); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsOtherAppsOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsOtherAppsOption.java index 2de4c224f..fa08176bc 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsOtherAppsOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsOtherAppsOption.java @@ -16,31 +16,30 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + public interface SupportsOtherAppsOption> extends Capabilities, CanSetCapability { - + String OTHER_APPS_OPTION = "otherApps"; /** * Set the location of the app(s) to install before running a test. * * @param apps is the apps to install. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#OTHER_APPS + * @return self instance for chaining. */ default T setOtherApps(String apps) { - return amend(MobileCapabilityType.OTHER_APPS, apps); + return amend(OTHER_APPS_OPTION, apps); } /** * Get the list of apps to install before running a test. * * @return String of apps to install. - * @see MobileCapabilityType#OTHER_APPS */ - default String getOtherApps() { - return (String) getCapability(MobileCapabilityType.OTHER_APPS); + default Optional getOtherApps() { + return Optional.ofNullable((String) getCapability(OTHER_APPS_OPTION)); } } diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsPlatformVersionOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsPlatformVersionOption.java new file mode 100644 index 000000000..fbb319f32 --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsPlatformVersionOption.java @@ -0,0 +1,45 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +public interface SupportsPlatformVersionOption> extends + Capabilities, CanSetCapability { + String PLATFORM_VERSION_OPTION = "platformVersion"; + + /** + * Set the version of the platform. + * + * @param version is the platform version. + * @return self instance for chaining. + */ + default T setPlatformVersion(String version) { + return amend(PLATFORM_VERSION_OPTION, version); + } + + /** + * Get the version of the platform. + * + * @return String representing the platform version. + */ + default Optional getPlatformVersion() { + return Optional.ofNullable((String) getCapability(PLATFORM_VERSION_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsPrintPageSourceOnFindFailureOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsPrintPageSourceOnFindFailureOption.java new file mode 100644 index 000000000..3d82738c5 --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/options/SupportsPrintPageSourceOnFindFailureOption.java @@ -0,0 +1,58 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.remote.options; + +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsPrintPageSourceOnFindFailureOption> extends + Capabilities, CanSetCapability { + String PRINT_PAGE_SOURCE_ON_FIND_FAILURE_OPTION = "printPageSourceOnFindFailure"; + + /** + * Set the app to print page source when a find operation fails. + * + * @return self instance for chaining. + */ + default T printPageSourceOnFindFailure() { + return setPrintPageSourceOnFindFailure(true); + } + + /** + * Set whether the app to print page source when a find operation fails. + * + * @param bool is whether to print page source. + * @return self instance for chaining. + */ + default T setPrintPageSourceOnFindFailure(boolean bool) { + return amend(PRINT_PAGE_SOURCE_ON_FIND_FAILURE_OPTION, bool); + } + + /** + * Get whether the app to print page source when a find operation fails. + * + * @return true if app prints page source. + */ + default Optional doesPrintPageSourceOnFindFailure() { + return Optional.ofNullable( + toSafeBoolean(getCapability(PRINT_PAGE_SOURCE_ON_FIND_FAILURE_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/remote/options/SupportsUdidOption.java b/src/main/java/io/appium/java_client/remote/options/SupportsUdidOption.java index bc6e59b37..fc1364b3d 100644 --- a/src/main/java/io/appium/java_client/remote/options/SupportsUdidOption.java +++ b/src/main/java/io/appium/java_client/remote/options/SupportsUdidOption.java @@ -16,29 +16,30 @@ package io.appium.java_client.remote.options; -import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.Capabilities; +import java.util.Optional; + public interface SupportsUdidOption> extends Capabilities, CanSetCapability { + String UDID_OPTION = "udid"; + /** * Set the id of the device. * * @param id is the unique device identifier. - * @return this MobileOptions, for chaining. - * @see MobileCapabilityType#UDID + * @return self instance, for chaining. */ default T setUdid(String id) { - return amend(MobileCapabilityType.UDID, id); + return amend(UDID_OPTION, id); } /** * Get the id of the device. * * @return String representing the unique device identifier. - * @see MobileCapabilityType#UDID */ - default String getUdid() { - return (String) getCapability(MobileCapabilityType.UDID); + default Optional getUdid() { + return Optional.ofNullable((String) getCapability(UDID_OPTION)); } }