diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileOptions.java b/src/main/java/io/appium/java_client/android/AndroidMobileOptions.java new file mode 100644 index 000000000..f92c045f7 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/AndroidMobileOptions.java @@ -0,0 +1,1733 @@ +/* + * 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; + +import io.appium.java_client.remote.AndroidMobileCapabilityType; +import io.appium.java_client.remote.MobileOptions; +import io.appium.java_client.remote.MobilePlatform; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.chrome.ChromeOptions; + +import java.time.Duration; +import java.util.List; + +public class AndroidMobileOptions extends MobileOptions { + + /** + * Creates new instance with platformName specified for Android. + */ + public AndroidMobileOptions() { + setPlatformName(MobilePlatform.ANDROID); + } + + /** + * Creates new instance with provided capabilities capabilities. + * + * @param source is Capabilities instance to merge into new instance + */ + public AndroidMobileOptions(Capabilities source) { + this(); + merge(source); + } + + /** + * Set the Timeout in milliseconds used to wait for adb command execution. + * + * @param duration is the number of milliseconds to wait for adb command execution. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ADB_EXEC_TIMEOUT + */ + public AndroidMobileOptions setAdbExecTimeout(Duration duration) { + return amend(AndroidMobileCapabilityType.ADB_EXEC_TIMEOUT, duration.toMillis()); + } + + /** + * Get the Timeout in milliseconds used to wait for adb command execution. + * + * @return Duration to wait for adb command execution. + * @see AndroidMobileCapabilityType#ADB_EXEC_TIMEOUT + */ + public Duration getAdbExecTimeout() { + Object duration = getCapability(AndroidMobileCapabilityType.ADB_EXEC_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofMillis((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofMillis(value); + } + + /** + * Set the port used to connect to the ADB server. + * + * @param port is the port to connect to the ADB server. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ADB_PORT + */ + public AndroidMobileOptions setAdbPort(Integer port) { + return amend(AndroidMobileCapabilityType.ADB_PORT, port); + } + + /** + * Get the port used to connect to the ADB server. + * + * @return Integer of the port used to connect to the ADB server. + * @see AndroidMobileCapabilityType#ADB_PORT + */ + public Integer getAdbPort() { + return (Integer) getCapability(AndroidMobileCapabilityType.ADB_PORT); + } + + /** + * Set the app to allow installation of a test package which has android:testOnly="true" in the manifest. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ALLOW_TEST_PACKAGES + */ + public AndroidMobileOptions setAllowTestPackages() { + return setAllowTestPackages(true); + } + + /** + * Set whether to allow installation of a test package which has android:testOnly="true" in the manifest. + * + * @param bool when true will be able install a test package marked testOnly. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ALLOW_TEST_PACKAGES + */ + public AndroidMobileOptions setAllowTestPackages(boolean bool) { + return amend(AndroidMobileCapabilityType.ALLOW_TEST_PACKAGES, bool); + } + + /** + * Get whether installation of a test package which has android:testOnly="true" in the manifest is allowed. + * + * @return true if able to install a test package marked testOnly. + * @see AndroidMobileCapabilityType#ALLOW_TEST_PACKAGES + */ + public boolean doesAllowTestPackages() { + return (boolean) getCapability(AndroidMobileCapabilityType.ALLOW_TEST_PACKAGES); + } + + /** + * Set the fully qualified instrumentation class. + * + * @param coverage is the fully qualified instrumentation class. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_COVERAGE + */ + public AndroidMobileOptions setAndroidCoverage(String coverage) { + return amend(AndroidMobileCapabilityType.ANDROID_COVERAGE, coverage); + } + + /** + * Get the fully qualified instrumentation class. + * + * @return String of the fully qualified instrumentation class. + * @see AndroidMobileCapabilityType#ANDROID_COVERAGE + */ + public String getAndroidCoverage() { + return (String) getCapability(AndroidMobileCapabilityType.ANDROID_COVERAGE); + } + + /** + * Set the broadcast action which is used to dump coverage into file system. + * + * @param coverage is the action to dump coverage into file system. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_COVERAGE_END_INTENT + */ + public AndroidMobileOptions setAndroidCoverageEndIntent(String coverage) { + return amend(AndroidMobileCapabilityType.ANDROID_COVERAGE_END_INTENT, coverage); + } + + /** + * Get the broadcast action which is used to dump coverage into file system. + * + * @return String of the broadcast action which is used to dump coverage into file system. + * @see AndroidMobileCapabilityType#ANDROID_COVERAGE_END_INTENT + */ + public String getAndroidCoverageEndIntent() { + return (String) getCapability(AndroidMobileCapabilityType.ANDROID_COVERAGE_END_INTENT); + } + + /** + * Set the timeout to wait for a device to become ready after booting. + * + * @param duration is the number of seconds to wait for a device to become ready after booting. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_DEVICE_READY_TIMEOUT + */ + public AndroidMobileOptions setAndroidDeviceReadyTimeout(Duration duration) { + return amend(AndroidMobileCapabilityType.ANDROID_DEVICE_READY_TIMEOUT, duration.getSeconds()); + } + + /** + * Get the timeout to wait for a device to become ready after booting. + * + * @return Duration to wait for a device to become ready after booting. + * @see AndroidMobileCapabilityType#ANDROID_DEVICE_READY_TIMEOUT + */ + public Duration getAndroidDeviceReadyTimeout() { + Object duration = getCapability(AndroidMobileCapabilityType.ANDROID_DEVICE_READY_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofSeconds((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofSeconds(value); + } + + /** + * Set the devtools socket name. + * + * @param activity is the devtools socket name. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_DEVICE_SOCKET + */ + public AndroidMobileOptions setAndroidDeviceSocket(String activity) { + return amend(AndroidMobileCapabilityType.ANDROID_DEVICE_SOCKET, activity); + } + + /** + * Get the devtools socket name. + * + * @return String of the devtools socket name. + * @see AndroidMobileCapabilityType#ANDROID_DEVICE_SOCKET + */ + public String getAndroidDeviceSocket() { + return (String) getCapability(AndroidMobileCapabilityType.ANDROID_DEVICE_SOCKET); + } + + /** + * Set the name of the directory on the device in which the apk will be pushed before install. + * + * @param path is the directory on the device in which the apk will be pushed before install. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_INSTALL_PATH + */ + public AndroidMobileOptions setAndroidInstallPath(String path) { + return amend(AndroidMobileCapabilityType.ANDROID_INSTALL_PATH, path); + } + + /** + * Get the name of the directory on the device in which the apk will be pushed before install. + * + * @return String of the name of the directory on the device in which the apk will be pushed before install. + * @see AndroidMobileCapabilityType#ANDROID_INSTALL_PATH + */ + public String getAndroidInstallPath() { + return (String) getCapability(AndroidMobileCapabilityType.ANDROID_INSTALL_PATH); + } + + /** + * Set the timeout to wait for an apk to install to the device. + * + * @param duration is the number of milliseconds to wait for an apk to install to the device. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_INSTALL_TIMEOUT + */ + public AndroidMobileOptions setAndroidInstallTimeout(Duration duration) { + return amend(AndroidMobileCapabilityType.ANDROID_INSTALL_TIMEOUT, duration.toMillis()); + } + + /** + * Get the timeout to wait for an apk to install to the device. + * + * @return Duration to wait for an apk to install to the device. + * @see AndroidMobileCapabilityType#ANDROID_INSTALL_TIMEOUT + */ + public Duration getAndroidInstallTimeout() { + Object duration = getCapability(AndroidMobileCapabilityType.ANDROID_INSTALL_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofMillis((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofMillis(value); + } + + /** + * Set the app to allow for correct handling of orientation on landscape-oriented devices. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_NATURAL_ORIENTATION + */ + public AndroidMobileOptions setAndroidNaturalOrientation() { + return setAndroidNaturalOrientation(true); + } + + /** + * Set whether to allow for correct handling of orientation on landscape-oriented devices. + * + * @param bool when true allows for correct handling of orientation on landscape-oriented devices. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_NATURAL_ORIENTATION + */ + public AndroidMobileOptions setAndroidNaturalOrientation(boolean bool) { + return amend(AndroidMobileCapabilityType.ANDROID_NATURAL_ORIENTATION, bool); + } + + /** + * Get whether correct handling of orientation on landscape-oriented devices is allowed. + * + * @return true if correct handling of orientation on landscape-oriented devices is allowed. + * @see AndroidMobileCapabilityType#ANDROID_NATURAL_ORIENTATION + */ + public boolean isAndroidNaturalOrientation() { + return (boolean) getCapability(AndroidMobileCapabilityType.ANDROID_NATURAL_ORIENTATION); + } + + /** + * Set the name of the directory on the device in which the screenshot will be put. + * + * @param path is the directory on the device in which the screenshot will be put. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ANDROID_SCREENSHOT_PATH + */ + public AndroidMobileOptions setAndroidScreenshotPath(String path) { + return amend(AndroidMobileCapabilityType.ANDROID_SCREENSHOT_PATH, path); + } + + /** + * Get the name of the directory on the device in which the screenshot will be put. + * + * @return String of the name of the directory on the device in which the screenshot will be put. + * @see AndroidMobileCapabilityType#ANDROID_SCREENSHOT_PATH + */ + public String getAndroidScreenshotPath() { + return (String) getCapability(AndroidMobileCapabilityType.ANDROID_SCREENSHOT_PATH); + } + + /** + * Set the activity name for the Android activity you want to launch from your package. + * + * @param activity is the name of the activity to launch from the package. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#APP_ACTIVITY + */ + public AndroidMobileOptions setAppActivity(String activity) { + return amend(AndroidMobileCapabilityType.APP_ACTIVITY, activity); + } + + /** + * Get the activity name for the Android activity you want to launch from your package. + * + * @return String of the activity name for the Android activity you want to launch from your package. + * @see AndroidMobileCapabilityType#APP_ACTIVITY + */ + public String getAppActivity() { + return (String) getCapability(AndroidMobileCapabilityType.APP_ACTIVITY); + } + + /** + * Set the Java package of the Android app you want to run. + * + * @param pkg is the Android app you want to run. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#APP_PACKAGE + */ + public AndroidMobileOptions setAppPackage(String pkg) { + return amend(AndroidMobileCapabilityType.APP_PACKAGE, pkg); + } + + /** + * Get the Java package of the Android app you want to run. + * + * @return String of the Java package of the Android app you want to run. + * @see AndroidMobileCapabilityType#APP_PACKAGE + */ + public String getAppPackage() { + return (String) getCapability(AndroidMobileCapabilityType.APP_PACKAGE); + } + + /** + * Set the activity name/names, comma separated, for the Android activity you want to wait for. + * + * @param activity is the comma separated activity names for activities to wait for. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#APP_WAIT_ACTIVITY + */ + public AndroidMobileOptions setAppWaitActivity(String activity) { + return amend(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, activity); + } + + /** + * Get the activity name/names, comma separated, for the Android activity to wait for. + * + * @return String of comma separated activity names for the Android activity to wait for. + * @see AndroidMobileCapabilityType#APP_WAIT_ACTIVITY + */ + public String getAppWaitActivity() { + return (String) getCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY); + } + + /** + * Set the Timeout used to wait for the appWaitActivity to launch. + * + * @param duration is the number of milliseconds to wait for the appWaitActivity to launch. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#APP_WAIT_DURATION + */ + public AndroidMobileOptions setAppWaitDuration(Duration duration) { + return amend(AndroidMobileCapabilityType.APP_WAIT_DURATION, duration.toMillis()); + } + + /** + * Get the timeout used to wait for the appWaitActivity to launch. + * + * @return Duration to wait for the appWaitActivity to launch. + * @see AndroidMobileCapabilityType#APP_WAIT_DURATION + */ + public Duration getAppWaitDuration() { + Object duration = getCapability(AndroidMobileCapabilityType.APP_WAIT_DURATION); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofMillis((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofMillis(value); + } + + /** + * Set the Java package of the Android app to wait for. + * + * @param pkg is the package of the app to wait for. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#APP_WAIT_PACKAGE + */ + public AndroidMobileOptions setAppWaitPackage(String pkg) { + return amend(AndroidMobileCapabilityType.APP_WAIT_PACKAGE, pkg); + } + + /** + * Get the Java package of the Android app to wait for. + * + * @return String of the Java package of the Android app to wait for. + * @see AndroidMobileCapabilityType#APP_WAIT_PACKAGE + */ + public String getAppWaitPackage() { + return (String) getCapability(AndroidMobileCapabilityType.APP_WAIT_PACKAGE); + } + + /** + * Set Appium to automatically determine which permissions the app requires and grant them to the app on install. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AUTO_GRANT_PERMISSIONS + */ + public AndroidMobileOptions setAutoGrantPermissions() { + return setAutoGrantPermissions(true); + } + + /** + * Set whether required permissions are determined and granted automatically. + * + * @param bool is true if required app permissions are automatically determined and granted. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AUTO_GRANT_PERMISSIONS + */ + public AndroidMobileOptions setAutoGrantPermissions(boolean bool) { + return amend(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, bool); + } + + /** + * Get whether required permissions are determined and granted automatically. + * + * @return true if required app permissions are automatically determined and granted. + * @see AndroidMobileCapabilityType#AUTO_GRANT_PERMISSIONS + */ + public boolean doesAutoGrantPermissions() { + return (boolean) getCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS); + } + + /** + * Set the app to initialize automatically. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AUTO_LAUNCH + */ + public AndroidMobileOptions setAutoLaunch() { + return setAutoLaunch(true); + } + + /** + * Set whether the app will initialize automatically. + * + * @param bool is true if the app automatically initializes. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AUTO_LAUNCH + */ + public AndroidMobileOptions setAutoLaunch(boolean bool) { + return amend(AndroidMobileCapabilityType.AUTO_LAUNCH, bool); + } + + /** + * Get whether the app will initialize automatically. + * + * @return true if the app automatically initializes. + * @see AndroidMobileCapabilityType#AUTO_LAUNCH + */ + public boolean doesAutoLaunch() { + return (boolean) getCapability(AndroidMobileCapabilityType.AUTO_LAUNCH); + } + + /** + * Set the amount of time to wait for Webview context to become active. + * + * @param duration is the number of milliseconds to wait for Webview context to become active. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AUTO_WEBVIEW_TIMEOUT + */ + public AndroidMobileOptions setAutoWebviewTimeout(Duration duration) { + return amend(AndroidMobileCapabilityType.AUTO_WEBVIEW_TIMEOUT, duration.toMillis()); + } + + /** + * Get the amount of time to wait for Webview context to become active. + * + * @return Duration to wait for Webview context to become active. + * @see AndroidMobileCapabilityType#AUTO_WEBVIEW_TIMEOUT + */ + public Duration getAutoWebviewTimeout() { + Object duration = getCapability(AndroidMobileCapabilityType.AUTO_WEBVIEW_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofMillis((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofMillis(value); + } + + /** + * Set the name of avd to launch. + * + * @param name is the name of avd to launch. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AVD + */ + public AndroidMobileOptions setAvd(String name) { + return amend(AndroidMobileCapabilityType.AVD, name); + } + + /** + * Get the name of avd to launch. + * + * @return String of the name of avd to launch. + * @see AndroidMobileCapabilityType#AVD + */ + public String getAvd() { + return (String) getCapability(AndroidMobileCapabilityType.AVD); + } + + /** + * Set the additional emulator arguments used when launching an avd. + * + * @param args is the additional arguments for launching avd on emulator. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AVD_ARGS + */ + public AndroidMobileOptions setAvdArgs(String args) { + return amend(AndroidMobileCapabilityType.AVD_ARGS, args); + } + + /** + * Get the additional emulator arguments used when launching an avd. + * + * @return String of the additional emulator arguments used when launching an avd. + * @see AndroidMobileCapabilityType#AVD_ARGS + */ + public String getAvdArgs() { + return (String) getCapability(AndroidMobileCapabilityType.AVD_ARGS); + } + + /** + * Set the wait time for an avd to launch and connect to ADB. + * + * @param duration is the number of milliseconds to wait for an avd to launch and connect to ADB. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AVD_LAUNCH_TIMEOUT + */ + public AndroidMobileOptions setAvdLaunchTimeout(Duration duration) { + return amend(AndroidMobileCapabilityType.AVD_LAUNCH_TIMEOUT, duration.toMillis()); + } + + /** + * Get the wait time for an avd to launch and connect to ADB. + * + * @return Duration to wait for an avd to launch and connect to ADB. + * @see AndroidMobileCapabilityType#AVD_LAUNCH_TIMEOUT + */ + public Duration getAvdLaunchTimeout() { + Object duration = getCapability(AndroidMobileCapabilityType.AVD_LAUNCH_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofMillis((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofMillis(value); + } + + /** + * Set the wait time for an avd to finish its boot animations. + * + * @param duration is the number of milliseconds to wait for an avd to finish its boot animations. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#AVD_READY_TIMEOUT + */ + public AndroidMobileOptions setAvdReadyTimeout(Duration duration) { + return amend(AndroidMobileCapabilityType.AVD_READY_TIMEOUT, duration.toMillis()); + } + + /** + * Get the the wait time for an avd to finish its boot animations. + * + * @return Duration to wait for an avd to finish its boot animations. + * @see AndroidMobileCapabilityType#AVD_READY_TIMEOUT + */ + public Duration getAvdReadyTimeout() { + Object duration = getCapability(AndroidMobileCapabilityType.AVD_READY_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofMillis((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofMillis(value); + } + + /** + * Set the Android build-tools version to be something different than the default. + * + * @param version is the version of Android build-tools to use. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#BUILD_TOOLS_VERSION + */ + public AndroidMobileOptions setBuildToolsVersion(String version) { + return amend(AndroidMobileCapabilityType.BUILD_TOOLS_VERSION, version); + } + + /** + * Get the Android build-tools version to be something different than the default. + * + * @return String of the Android build-tools version to be something different than the default. + * @see AndroidMobileCapabilityType#BUILD_TOOLS_VERSION + */ + public String getBuildToolsVersion() { + return (String) getCapability(AndroidMobileCapabilityType.BUILD_TOOLS_VERSION); + } + + /** + * Set the arguments to be passed to the chromedriver binary when it's run by Appium.. + * + * @param args is the List of arguments to be passed to the chromedriver. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_ARGS + */ + public AndroidMobileOptions setChromedriverArgs(List args) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_ARGS, args); + } + + /** + * Get the arguments to be passed to the chromedriver binary when it's run by Appium.. + * + * @return list of String arguments to be passed to the chromedriver binary when it's run by Appium. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_ARGS + */ + public List getChromedriverArgs() { + return (List) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_ARGS); + } + + /** + * Set the file location which maps Chromedriver versions to the minimum Chrome version that it supports. + * + * @param path is the absolute path to a file mapping Chromedriver versions to Chrome versions. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_CHROME_MAPPING_FILE + */ + public AndroidMobileOptions setChromedriverChromeMappingFile(String path) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_CHROME_MAPPING_FILE, path); + } + + /** + * Get the file location which maps Chromedriver versions to the minimum Chrome version that it supports. + * + * @return String of the file location which maps Chromedriver versions to the minimum supported Chrome version. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_CHROME_MAPPING_FILE + */ + public String getChromedriverChromeMappingFile() { + return (String) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_CHROME_MAPPING_FILE); + } + + /** + * Set the chromedriver flag --disable-build-check for Chrome webview tests. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_DISABLE_BUILD_CHECK + */ + public AndroidMobileOptions setChromedriverDisableBuildCheck() { + return setChromedriverDisableBuildCheck(true); + } + + /** + * Set whether chromedriver flag --disable-build-check is added for Chrome webview tests. + * + * @param bool when true adds --disable-build-check for Chrome webview. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_DISABLE_BUILD_CHECK + */ + public AndroidMobileOptions setChromedriverDisableBuildCheck(boolean bool) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_DISABLE_BUILD_CHECK, bool); + } + + /** + * Get whether chromedriver flag --disable-build-check is added for Chrome webview tests. + * + * @return true if --disable-build-check for Chrome webview is added. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_DISABLE_BUILD_CHECK + */ + public boolean doesChromedriverDisableBuildCheck() { + return (boolean) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_DISABLE_BUILD_CHECK); + } + + /** + * Set the path to webdriver executable. + * + * @param path is the absolute local path to webdriver executable. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_EXECUTABLE + */ + public AndroidMobileOptions setChromedriverExecutable(String path) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, path); + } + + /** + * Get the path to webdriver executable. + * + * @return String of the path to webdriver executable. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_EXECUTABLE + */ + public String getChromedriverExecutable() { + return (String) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE); + } + + /** + * Set the directory to look for Chromedriver executables in, for automatic discovery of compatible Chromedrivers. + * + * @param dir is the absolute path of the directory to automatically discover compatible Chromedriver executable. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_EXECUTABLE_DIR + */ + public AndroidMobileOptions setChromedriverExecutableDir(String dir) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE_DIR, dir); + } + + /** + * Get the directory to look for Chromedriver executables in, for automatic discovery of compatible Chromedrivers. + * + * @return String of the directory of Chromedriver executables. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_EXECUTABLE_DIR + */ + public String getChromedriverExecutableDir() { + return (String) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE_DIR); + } + + /** + * Set the port to start Chromedriver on. + * + * @param port is the number of the port to use for Chromedriver. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_PORT + */ + public AndroidMobileOptions setChromedriverPort(Integer port) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_PORT, port); + } + + /** + * Get the port Chromedriver starts on. + * + * @return Integer of the port Chromedriver starts on. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_PORT + */ + public int getChromedriverPort() { + return (Integer) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_PORT); + } + + /** + * Set the valid ports for Appium to use for communication with Chromedrivers. + * + * @param ports is the list of ports for Appium to use with Chromedrivers. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_PORTS + */ + public AndroidMobileOptions setChromedriverPorts(List ports) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_PORTS, ports); + } + + /** + * Get the valid ports for Appium to use for communication with Chromedrivers. + * + * @return list of Integers or Array of Integers for the valid ports to use for communication with Chromedrivers. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_PORTS + */ + public List getChromedriverPorts() { + return (List) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_PORTS); + } + + /** + * Set the app to bypass automatic Chromedriver configuration and use the version that comes downloaded with Appium. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_USE_SYSTEM_EXECUTABLE + */ + public AndroidMobileOptions setChromedriverUseSystemExecutable() { + return setChromedriverUseSystemExecutable(true); + } + + /** + * Set whether to bypass automatic Chromedriver configuration and use the version that comes downloaded with Appium. + * + * @param bool when true uses the version of Chromedriver that comes with Appium. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_USE_SYSTEM_EXECUTABLE + */ + public AndroidMobileOptions setChromedriverUseSystemExecutable(boolean bool) { + return amend(AndroidMobileCapabilityType.CHROMEDRIVER_USE_SYSTEM_EXECUTABLE, bool); + } + + /** + * Get whether to bypass automatic Chromedriver configuration and use the version that comes downloaded with Appium. + * + * @return true if using the version of Chromedriver that comes with Appium. + * @see AndroidMobileCapabilityType#CHROMEDRIVER_USE_SYSTEM_EXECUTABLE + */ + public boolean doesChromedriverUseSystemExecutable() { + return (boolean) getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_USE_SYSTEM_EXECUTABLE); + } + + /** + * Set the chromeOptions capability for ChromeDriver. + * + * @param opts is the chromeoptions for ChromeDriver. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#CHROME_OPTIONS + */ + public AndroidMobileOptions setChromeOptions(ChromeOptions opts) { + return amend(AndroidMobileCapabilityType.CHROME_OPTIONS, opts); + } + + /** + * Get the chromeOptions capability for ChromeDriver. + * + * @return ChromeOptions set for use with ChromeDriver. + * @see AndroidMobileCapabilityType#CHROME_OPTIONS + */ + public Object getChromeOptions() { + return getCapability(ChromeOptions.CAPABILITY); + } + + /** + * Set the timeout for device to become ready. + * + * @param duration is the number of seconds to wait for the device to become ready. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#DEVICE_READY_TIMEOUT + */ + public AndroidMobileOptions setDeviceReadyTimeout(Duration duration) { + return amend(AndroidMobileCapabilityType.DEVICE_READY_TIMEOUT, duration.getSeconds()); + } + + /** + * Get the timeout for device to become ready. + * + * @return Duration to wait for device to become ready. + * @see AndroidMobileCapabilityType#DEVICE_READY_TIMEOUT + */ + public Duration getDeviceReadyTimeout() { + Object duration = getCapability(AndroidMobileCapabilityType.DEVICE_READY_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofSeconds((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofSeconds(value); + } + + /** + * Set the application to disable Android watchers for when application is not responding or crashes. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#DISABLE_ANDROID_WATCHERS + */ + public AndroidMobileOptions setDisableAndroidWatchers() { + return setDisableAndroidWatchers(true); + } + + /** + * Set whether the application disables Android watchers for when application is not responding or crashes. + * + * @param bool when true disables Android watchers for when application is not responding or crashes. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#DISABLE_ANDROID_WATCHERS + */ + public AndroidMobileOptions setDisableAndroidWatchers(boolean bool) { + return amend(AndroidMobileCapabilityType.DISABLE_ANDROID_WATCHERS, bool); + } + + /** + * Get whether the application disables Android watchers for when application is not responding or crashes. + * + * @return true if Android watchers for when application is not responding or crashes are disabled. + * @see AndroidMobileCapabilityType#DISABLE_ANDROID_WATCHERS + */ + public boolean doesDisableAndroidWatchers() { + return (boolean) getCapability(AndroidMobileCapabilityType.DISABLE_ANDROID_WATCHERS); + } + + /** + * Set the device animation scale to zero. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#DISABLE_WINDOW_ANIMATION + */ + public AndroidMobileOptions setDisableWindowAnimation() { + return setDisableWindowAnimation(true); + } + + /** + * Set whether the application has device animation scale of zero. + * + * @param bool when true has device animation scale of zero. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#DISABLE_WINDOW_ANIMATION + */ + public AndroidMobileOptions setDisableWindowAnimation(boolean bool) { + return amend(AndroidMobileCapabilityType.DISABLE_WINDOW_ANIMATION, bool); + } + + /** + * Get whether the application has device animation scale of zero. + * + * @return true if device animation scale is zero. + * @see AndroidMobileCapabilityType#DISABLE_WINDOW_ANIMATION + */ + public boolean doesDisableWindowAnimation() { + return (boolean) getCapability(AndroidMobileCapabilityType.DISABLE_WINDOW_ANIMATION); + } + + /** + * Set the app not to stop the process of the app under test, before starting the app using adb. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#DONT_STOP_APP_ON_RESET + */ + public AndroidMobileOptions setDontStopAppOnReset() { + return setDontStopAppOnReset(true); + } + + /** + * Set whether the app process is not stopped before starting using adb. + * + * @param bool when true does not stop the process of the app under test before starting the app using adb. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#DONT_STOP_APP_ON_RESET + */ + public AndroidMobileOptions setDontStopAppOnReset(boolean bool) { + return amend(AndroidMobileCapabilityType.DONT_STOP_APP_ON_RESET, bool); + } + + /** + * Get whether the app process is not stopped before starting using adb. + * + * @return true if the process of the app under test does not stop before starting the app using adb. + * @see AndroidMobileCapabilityType#DONT_STOP_APP_ON_RESET + */ + public boolean isDontStopAppOnReset() { + return (boolean) getCapability(AndroidMobileCapabilityType.DONT_STOP_APP_ON_RESET); + } + + /** + * Set to always install the current application build independently of the currently installed version of it. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ENFORCE_APP_INSTALL + */ + public AndroidMobileOptions setEnforceAppInstall() { + return setEnforceAppInstall(true); + } + + /** + * Set whether to always install the current application build independently of the currently installed version. + * + * @param bool when true will install the current application build independently of the installed version. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ENFORCE_APP_INSTALL + */ + public AndroidMobileOptions setEnforceAppInstall(boolean bool) { + return amend(AndroidMobileCapabilityType.ENFORCE_APP_INSTALL, bool); + } + + /** + * Get whether the current application build is always isntalled independently of the currently installed version. + * + * @return true if the current application build is installed independently of the currently installed version. + * @see AndroidMobileCapabilityType#ENFORCE_APP_INSTALL + */ + public boolean doesEnforceAppInstall() { + return (boolean) getCapability(AndroidMobileCapabilityType.ENFORCE_APP_INSTALL); + } + + /** + * Set the app to augment its webview detection with page detection. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ENSURE_WEBVIEWS_HAVE_PAGES + */ + public AndroidMobileOptions setEnsureWebviewsHavePages() { + return setEnsureWebviewsHavePages(true); + } + + /** + * Set whether to augment webview detection with page detection. + * + * @param bool when true augments webview detection with page detection. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#ENSURE_WEBVIEWS_HAVE_PAGES + */ + public AndroidMobileOptions setEnsureWebviewsHavePages(boolean bool) { + return amend(AndroidMobileCapabilityType.ENSURE_WEBVIEWS_HAVE_PAGES, bool); + } + + /** + * Get whether to augment webview detection with page detection. + * + * @return true if webview detection is augmented with page detection. + * @see AndroidMobileCapabilityType#ENSURE_WEBVIEWS_HAVE_PAGES + */ + public boolean doesEnsureWebviewsHavePages() { + return (boolean) getCapability(AndroidMobileCapabilityType.ENSURE_WEBVIEWS_HAVE_PAGES); + } + + /** + * Set the app to use GPS location for emulators. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#GPS_ENABLED + */ + public AndroidMobileOptions setGpsEnabled() { + return setGpsEnabled(true); + } + + /** + * Set whether to use GPS location for emulators. + * + * @param bool when true will enable GPS location for emulators. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#GPS_ENABLED + */ + public AndroidMobileOptions setGpsEnabled(boolean bool) { + return amend(AndroidMobileCapabilityType.GPS_ENABLED, bool); + } + + /** + * Get whether to use GPS location for emulators. + * + * @return true if GPS location for emulators is enabled. + * @see AndroidMobileCapabilityType#GPS_ENABLED + */ + public boolean isGpsEnabled() { + return (boolean) getCapability(AndroidMobileCapabilityType.GPS_ENABLED); + } + + /** + * Set the accessibility commands to run faster by ignoring some elements. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#IGNORE_UNIMPORTANT_VIEWS + */ + public AndroidMobileOptions setIgnoreUnimportantViews() { + return setIgnoreUnimportantViews(true); + } + + /** + * Set whether accessibility commands run faster by ignoring some elements. + * + * @param bool when true will ignore some elements to improve performance. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#IGNORE_UNIMPORTANT_VIEWS + */ + public AndroidMobileOptions setIgnoreUnimportantViews(boolean bool) { + return amend(AndroidMobileCapabilityType.IGNORE_UNIMPORTANT_VIEWS, bool); + } + + /** + * Get whether accessibility commands run faster by ignoring some elements. + * + * @return true if some elements are ignored to improve performance. + * @see AndroidMobileCapabilityType#IGNORE_UNIMPORTANT_VIEWS + */ + public boolean doesIgnoreUnimportantViews() { + return (boolean) getCapability(AndroidMobileCapabilityType.IGNORE_UNIMPORTANT_VIEWS); + } + + /** + * Set the intent action which will be used to start activity. + * + * @param action is the action used to start the activity. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#INTENT_ACTION + */ + public AndroidMobileOptions setIntentAction(String action) { + return amend(AndroidMobileCapabilityType.INTENT_ACTION, action); + } + + /** + * Get the intent action which will be used to start activity. + * + * @return String of the intent action which will be used to start activity. + * @see AndroidMobileCapabilityType#INTENT_ACTION + */ + public String getIntentAction() { + return (String) getCapability(AndroidMobileCapabilityType.INTENT_ACTION); + } + + /** + * Set the intent category which will be used to start activity. + * + * @param category is the category used to start activity. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#INTENT_CATEGORY + */ + public AndroidMobileOptions setIntentCategory(String category) { + return amend(AndroidMobileCapabilityType.INTENT_CATEGORY, category); + } + + /** + * Get the intent category which will be used to start activity. + * + * @return String of the intent category which will be used to start activity. + * @see AndroidMobileCapabilityType#INTENT_CATEGORY + */ + public String getIntentCategory() { + return (String) getCapability(AndroidMobileCapabilityType.INTENT_CATEGORY); + } + + /** + * Set the flags that will be used to start activity. + * + * @param flags is the flags used to start activity. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#INTENT_FLAGS + */ + public AndroidMobileOptions setIntentFlags(String flags) { + return amend(AndroidMobileCapabilityType.INTENT_FLAGS, flags); + } + + /** + * Get the flags that will be used to start activity. + * + * @return String of the flags that will be used to start activity. + * @see AndroidMobileCapabilityType#INTENT_FLAGS + */ + public String getIntentFlags() { + return (String) getCapability(AndroidMobileCapabilityType.INTENT_FLAGS); + } + + /** + * Set the emulator to not display the screen. + * + * @param bool when true will not display the emulator screen. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#IS_HEADLESS + */ + public AndroidMobileOptions setIsHeadless(boolean bool) { + return amend(AndroidMobileCapabilityType.IS_HEADLESS, bool); + } + + /** + * Get the emulator to not display the screen. + * + * @return true if emulator is not to display the screen. + * @see AndroidMobileCapabilityType#IS_HEADLESS + */ + public boolean isHeadless() { + return (boolean) getCapability(AndroidMobileCapabilityType.IS_HEADLESS); + } + + /** + * Set the alias for the key. + * + * @param alias is the key alias. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#KEY_ALIAS + */ + public AndroidMobileOptions setKeyAlias(String alias) { + return amend(AndroidMobileCapabilityType.KEY_ALIAS, alias); + } + + /** + * Get the alias for the key. + * + * @return String of the key alias. + * @see AndroidMobileCapabilityType#KEY_ALIAS + */ + public String getKeyAlias() { + return (String) getCapability(AndroidMobileCapabilityType.KEY_ALIAS); + } + + /** + * Set the password for the key. + * + * @param password is the key password. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#KEY_PASSWORD + */ + public AndroidMobileOptions setKeyPassword(String password) { + return amend(AndroidMobileCapabilityType.KEY_PASSWORD, password); + } + + /** + * Get the password for the key. + * + * @return String of the key password. + * @see AndroidMobileCapabilityType#KEY_PASSWORD + */ + public String getKeyPassword() { + return (String) getCapability(AndroidMobileCapabilityType.KEY_PASSWORD); + } + + /** + * Set the password for custom keystore. + * + * @param password is the password for the custom keystore. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#KEYSTORE_PASSWORD + */ + public AndroidMobileOptions setKeystorePassword(String password) { + return amend(AndroidMobileCapabilityType.KEYSTORE_PASSWORD, password); + } + + /** + * Get the password for custom keystore. + * + * @return String of the custom keystore password. + * @see AndroidMobileCapabilityType#KEYSTORE_PASSWORD + */ + public String getKeystorePassword() { + return (String) getCapability(AndroidMobileCapabilityType.KEYSTORE_PASSWORD); + } + + /** + * Set the path to custom keystore. + * + * @param path is the path to the custom keystore. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#KEYSTORE_PATH + */ + public AndroidMobileOptions setKeystorePath(String path) { + return amend(AndroidMobileCapabilityType.KEYSTORE_PATH, path); + } + + /** + * Get the path to custom keystore. + * + * @return String of the custom keystore path. + * @see AndroidMobileCapabilityType#KEYSTORE_PATH + */ + public String getKeystorePath() { + return (String) getCapability(AndroidMobileCapabilityType.KEYSTORE_PATH); + } + + /** + * Set the locale script. + * + * @param script is the locale script. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#LOCALE_SCRIPT + */ + public AndroidMobileOptions setLocaleScript(String script) { + return amend(AndroidMobileCapabilityType.LOCALE_SCRIPT, script); + } + + /** + * Get the locale script. + * + * @return String of the locale script. + * @see AndroidMobileCapabilityType#LOCALE_SCRIPT + */ + public String getLocaleScript() { + return (String) getCapability(AndroidMobileCapabilityType.LOCALE_SCRIPT); + } + + /** + * Set the web context to use native (adb) method for taking a screenshot. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#NATIVE_WEB_SCREENSHOT + */ + public AndroidMobileOptions setNativeWebScreenshot() { + return setNativeWebScreenshot(true); + } + + /** + * Set whether the web context uses native (adb) method for taking a screenshot or proxies to ChromeDriver. + * + * @param bool when true uses the native method for taking a screenshot. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#NATIVE_WEB_SCREENSHOT + */ + public AndroidMobileOptions setNativeWebScreenshot(boolean bool) { + return amend(AndroidMobileCapabilityType.NATIVE_WEB_SCREENSHOT, bool); + } + + /** + * Get whether the web context uses native (adb) method for taking a screenshot or proxies to ChromeDriver. + * + * @return true if using the native method for taking a screenshot. + * @see AndroidMobileCapabilityType#NATIVE_WEB_SCREENSHOT + */ + public boolean doesNativeWebScreenshot() { + return (boolean) getCapability(AndroidMobileCapabilityType.NATIVE_WEB_SCREENSHOT); + } + + /** + * Set the network speed emulation. + * + * @param speed is the network speed emulation. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#NETWORK_SPEED + */ + public AndroidMobileOptions setNetworkSpeed(String speed) { + return amend(AndroidMobileCapabilityType.NETWORK_SPEED, speed); + } + + /** + * Set the network speed emulation. + * + * @param speed is the network speed emulation. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#NETWORK_SPEED + */ + public AndroidMobileOptions setNetworkSpeed(NetworkSpeed speed) { + return amend(AndroidMobileCapabilityType.NETWORK_SPEED, speed.name().toLowerCase()); + } + + /** + * Get the network speed emulation. + * + * @return String of the network speed emulation. + * @see AndroidMobileCapabilityType#NETWORK_SPEED + */ + public String getNetworkSpeed() { + return (String) getCapability(AndroidMobileCapabilityType.NETWORK_SPEED); + } + + /** + * Set the app to skip checking and signing with debug keys. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#NO_SIGN + */ + public AndroidMobileOptions setNoSign() { + return setNoSign(true); + } + + /** + * Set whether to skip checking and signing the app with debug keys. + * + * @param bool when true skips checking and signing the app with debug keys. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#NO_SIGN + */ + public AndroidMobileOptions setNoSign(boolean bool) { + return amend(AndroidMobileCapabilityType.NO_SIGN, bool); + } + + /** + * Get whether to skip checking and signing the app with debug keys. + * + * @return true if checking and signing the app with debug keys is skipped + * @see AndroidMobileCapabilityType#NO_SIGN + */ + public boolean isNoSign() { + return (boolean) getCapability(AndroidMobileCapabilityType.NO_SIGN); + } + + /** + * Set the additional intent arguments that will be used to start activity. + * + * @param arguments is the additional intent arguments that will be used to start activity. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#OPTIONAL_INTENT_ARGUMENTS + */ + public AndroidMobileOptions setOptionalIntentArguments(String arguments) { + return amend(AndroidMobileCapabilityType.OPTIONAL_INTENT_ARGUMENTS, arguments); + } + + /** + * Get the additional intent arguments that will be used to start activity. + * + * @return String of the additional intent arguments that will be used to start activity. + * @see AndroidMobileCapabilityType#OPTIONAL_INTENT_ARGUMENTS + */ + public String getOptionalIntentArguments() { + return (String) getCapability(AndroidMobileCapabilityType.OPTIONAL_INTENT_ARGUMENTS); + } + + /** + * Set the app to kill ChromeDriver session when moving to a non-ChromeDriver webview. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#RECREATE_CHROME_DRIVER_SESSIONS + */ + public AndroidMobileOptions setRecreateChromeDriverSessions() { + return setRecreateChromeDriverSessions(true); + } + + /** + * Set whether to kill ChromeDriver session when moving to a non-ChromeDriver webview. + * + * @param bool when true kills ChromeDriver session when moving to a non-ChromeDriver webview. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#RECREATE_CHROME_DRIVER_SESSIONS + */ + public AndroidMobileOptions setRecreateChromeDriverSessions(boolean bool) { + return amend(AndroidMobileCapabilityType.RECREATE_CHROME_DRIVER_SESSIONS, bool); + } + + /** + * Get whether to kill ChromeDriver session when moving to a non-ChromeDriver webview. + * + * @return true if kills ChromeDriver session when moving to a non-ChromeDriver webview. + * @see AndroidMobileCapabilityType#RECREATE_CHROME_DRIVER_SESSIONS + */ + public boolean doesRecreateChromeDriverSessions() { + return (boolean) getCapability(AndroidMobileCapabilityType.RECREATE_CHROME_DRIVER_SESSIONS); + } + + /** + * Set the optional remote ADB server host. + * + * @param host is the remote ADB server host. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#REMOTE_ADB_HOST + */ + public AndroidMobileOptions setRemoteAdbHost(String host) { + return amend(AndroidMobileCapabilityType.REMOTE_ADB_HOST, host); + } + + /** + * Get the optional remote ADB server host. + * + * @return String of . + * @see AndroidMobileCapabilityType#REMOTE_ADB_HOST + */ + public String getRemoteAdbHost() { + return (String) getCapability(AndroidMobileCapabilityType.REMOTE_ADB_HOST); + } + + /** + * Set the maximum number of remote cached apks which are pushed to the device-under-test's local storage. + * + * @param num is the maximum number of remote cached apks pushed to local storage. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#REMOTE_APPS_CACHE_LIMIT + */ + public AndroidMobileOptions setRemoteAppsCacheLimit(int num) { + return amend(AndroidMobileCapabilityType.REMOTE_APPS_CACHE_LIMIT, num); + } + + /** + * Get the maximum number of remote cached apks which are pushed to the device-under-test's local storage. + * + * @return Integer of the max number of remote cached apks pushed to local storage. + * @see AndroidMobileCapabilityType#REMOTE_APPS_CACHE_LIMIT + */ + public int getRemoteAppsCacheLimit() { + return (int) getCapability(AndroidMobileCapabilityType.REMOTE_APPS_CACHE_LIMIT); + } + + /** + * Set the keyboard to reset to its original state after running Unicode tests with unicodeKeyboard capability. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#RESET_KEYBOARD + */ + public AndroidMobileOptions setResetKeyboard() { + return setResetKeyboard(true); + } + + /** + * Set whether the keyboard resets to original state after running Unicode tests with unicodeKeyboard capability. + * + * @param bool when true resets the keyboard to its original state after running with unicodeKeyboard. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#RESET_KEYBOARD + */ + public AndroidMobileOptions setResetKeyboard(boolean bool) { + return amend(AndroidMobileCapabilityType.RESET_KEYBOARD, bool); + } + + /** + * Get whether the keyboard resets to original state after running Unicode tests with unicodeKeyboard capability. + * + * @return true if the keyboard is reset to its original state after running with unicodeKeyboard. + * @see AndroidMobileCapabilityType#RESET_KEYBOARD + */ + public boolean doesResetKeyboard() { + return (boolean) getCapability(AndroidMobileCapabilityType.RESET_KEYBOARD); + } + + /** + * Set the device to skip initialization including installation and running of Settings app and permissions. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#SKIP_DEVICE_INITIALIZATION + */ + public AndroidMobileOptions setSkipDeviceInitialization() { + return setSkipDeviceInitialization(true); + } + + /** + * Set whether to skip device initialization including installation and running of Settings app and permissions. + * + * @param bool when true skips device initialization. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#SKIP_DEVICE_INITIALIZATION + */ + public AndroidMobileOptions setSkipDeviceInitialization(boolean bool) { + return amend(AndroidMobileCapabilityType.SKIP_DEVICE_INITIALIZATION, bool); + } + + /** + * Get whether to skip device initialization including installation and running of Settings app and permissions. + * + * @return true if device initialization is skipped. + * @see AndroidMobileCapabilityType#SKIP_DEVICE_INITIALIZATION + */ + public boolean doesSkipDeviceInitialization() { + return (boolean) getCapability(AndroidMobileCapabilityType.SKIP_DEVICE_INITIALIZATION); + } + + /** + * Set the App to skip capturing logcat. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#SKIP_LOGCAT_CAPTURE + */ + public AndroidMobileOptions setSkipLogcatCapture() { + return setSkipLogcatCapture(true); + } + + /** + * Set whether to skip capturing logcat. + * + * @param bool when true does not capture logcat. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#SKIP_LOGCAT_CAPTURE + */ + public AndroidMobileOptions setSkipLogcatCapture(boolean bool) { + return amend(AndroidMobileCapabilityType.SKIP_LOGCAT_CAPTURE, bool); + } + + /** + * Get whether to skip capturing logcat. + * + * @return true if not capturing logcat. + * @see AndroidMobileCapabilityType#SKIP_LOGCAT_CAPTURE + */ + public boolean doesSkipLogcatCapture() { + return (boolean) getCapability(AndroidMobileCapabilityType.SKIP_LOGCAT_CAPTURE); + } + + /** + * Set the app to skip unlock during session creation. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#SKIP_UNLOCK + */ + public AndroidMobileOptions setSkipUnlock() { + return setSkipUnlock(true); + } + + /** + * Set whether to skip unlock during session creation. + * + * @param bool when true skips unlock during session creation. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#SKIP_UNLOCK + */ + public AndroidMobileOptions setSkipUnlock(boolean bool) { + return amend(AndroidMobileCapabilityType.SKIP_UNLOCK, bool); + } + + /** + * Get whether to skip unlock during session creation. + * + * @return true if unlock during session creation is skipped. + * @see AndroidMobileCapabilityType#SKIP_UNLOCK + */ + public boolean doesSkipUnlock() { + return (boolean) getCapability(AndroidMobileCapabilityType.SKIP_UNLOCK); + } + + /** + * Set the port used to connect to the driver. + * + * @param port is the port used to connect to the driver. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#SYSTEM_PORT + */ + public AndroidMobileOptions setSystemPort(Integer port) { + return amend(AndroidMobileCapabilityType.SYSTEM_PORT, port); + } + + /** + * Get the port used to connect to the driver. + * + * @return Integer of the port used to connect to the driver. + * @see AndroidMobileCapabilityType#SYSTEM_PORT + */ + public Integer getSystemPort() { + return (Integer) getCapability(AndroidMobileCapabilityType.SYSTEM_PORT); + } + + /** + * Set the packages to uninstall before installing apks. + * + * @param packages is the String of comma separated packages to uninstall before installing apks. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#UNINSTALL_OTHER_PACKAGES + */ + public AndroidMobileOptions setUninstallOtherPackages(String packages) { + return amend(AndroidMobileCapabilityType.UNINSTALL_OTHER_PACKAGES, packages); + } + + /** + * Get the list of packages to uninstall before installing apks. + * + * @return String of package(s) to uninstall before installing apks. + * @see AndroidMobileCapabilityType#UNINSTALL_OTHER_PACKAGES + */ + public String getUninstallOtherPackages() { + return (String) getCapability(AndroidMobileCapabilityType.UNINSTALL_OTHER_PACKAGES); + } + + /** + * Set the key pattern to unlock used by unlockType. + * + * @param key is the key pattern to unlock. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#UNLOCK_KEY + */ + public AndroidMobileOptions setUnlockKey(String key) { + return amend(AndroidMobileCapabilityType.UNLOCK_KEY, key); + } + + /** + * Get the key pattern to unlock used by unlockType. + * + * @return String of the key pattern to unlock used by unlockType. + * @see AndroidMobileCapabilityType#UNLOCK_KEY + */ + public String getUnlockKey() { + return (String) getCapability(AndroidMobileCapabilityType.UNLOCK_KEY); + } + + /** + * Set the device to unlock with particular lock pattern instead of just waking up the device with a helper app. + * + * @param type is the pattern to unlock the device. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#UNLOCK_TYPE + */ + public AndroidMobileOptions setUnlockType(String type) { + return amend(AndroidMobileCapabilityType.UNLOCK_TYPE, type); + } + + /** + * Set the device to unlock with particular lock pattern instead of just waking up the device with a helper app. + * + * @param type is the pattern to unlock the device. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#UNLOCK_TYPE + */ + public AndroidMobileOptions setUnlockType(UnlockType type) { + return amend(AndroidMobileCapabilityType.UNLOCK_TYPE, type.name().toLowerCase()); + } + + /** + * Get the device to unlock with particular lock pattern instead of just waking up the device with a helper app. + * + * @return String of the device to unlock with particular lock pattern. + * @see AndroidMobileCapabilityType#UNLOCK_TYPE + */ + public String getUnlockType() { + return (String) getCapability(AndroidMobileCapabilityType.UNLOCK_TYPE); + } + + /** + * Set to use a custom keystore to sign apks. + * + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#USE_KEYSTORE + */ + public AndroidMobileOptions setUseKeystore() { + return setUseKeystore(true); + } + + /** + * Set whether to use a custom keystore to sign apks. + * + * @param bool when true allows using a custom keystore to sign apks. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#USE_KEYSTORE + */ + public AndroidMobileOptions setUseKeystore(boolean bool) { + return amend(AndroidMobileCapabilityType.USE_KEYSTORE, bool); + } + + /** + * Get whether to use a custom keystore to sign apks. + * + * @return true if using a custom keystore to sign apks is allowed. + * @see AndroidMobileCapabilityType#USE_KEYSTORE + */ + public boolean doesUseKeystore() { + return (boolean) getCapability(AndroidMobileCapabilityType.USE_KEYSTORE); + } + + /** + * Set the TCP port for communication with the webview. + * + * @param port is the port for communicating with the webview. + * @return this MobileOptions, for chaining. + * @see AndroidMobileCapabilityType#WEBVIEW_DEVTOOLS_PORT + */ + public AndroidMobileOptions setWebviewDevtoolsPort(Integer port) { + return amend(AndroidMobileCapabilityType.WEBVIEW_DEVTOOLS_PORT, port); + } + + /** + * Get the TCP port for communication with the webview. + * + * @return Integer of the TCP port for communication with the webview. + * @see AndroidMobileCapabilityType#WEBVIEW_DEVTOOLS_PORT + */ + public Integer getWebviewDevtoolsPort() { + return (Integer) getCapability(AndroidMobileCapabilityType.WEBVIEW_DEVTOOLS_PORT); + } +} diff --git a/src/main/java/io/appium/java_client/android/UnlockType.java b/src/main/java/io/appium/java_client/android/UnlockType.java new file mode 100644 index 000000000..6b4fbce93 --- /dev/null +++ b/src/main/java/io/appium/java_client/android/UnlockType.java @@ -0,0 +1,5 @@ +package io.appium.java_client.android; + +public enum UnlockType { + PIN, PASSWORD, PATTERN, FINGERPRINT +} diff --git a/src/main/java/io/appium/java_client/ios/IOSMobileOptions.java b/src/main/java/io/appium/java_client/ios/IOSMobileOptions.java new file mode 100644 index 000000000..e419767ca --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/IOSMobileOptions.java @@ -0,0 +1,32 @@ +/* + * 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.ios; + +import io.appium.java_client.remote.MobileOptions; +import io.appium.java_client.remote.MobilePlatform; +import org.openqa.selenium.Capabilities; + +public class IOSMobileOptions extends MobileOptions { + public IOSMobileOptions() { + setPlatformName(MobilePlatform.IOS); + } + + public IOSMobileOptions(Capabilities source) { + this(); + merge(source); + } +} diff --git a/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java index 1f0b0ccf2..0650115f2 100644 --- a/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java @@ -124,7 +124,7 @@ public interface MobileCapabilityType extends CapabilityType { String EVENT_TIMINGS = "eventTimings"; /** - * This is the flag which forces server to switch to the mobile WSONWP. + * This is the flag which forces server to switch to the mobile JSONWP. * If {@code false} then it is switched to W3C mode. */ String FORCE_MJSONWP = "forceMjsonwp"; diff --git a/src/main/java/io/appium/java_client/remote/MobileOptions.java b/src/main/java/io/appium/java_client/remote/MobileOptions.java new file mode 100644 index 000000000..1833c0027 --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/MobileOptions.java @@ -0,0 +1,521 @@ +/* + * 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; + +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; +import java.util.List; + +public class MobileOptions> extends MutableCapabilities { + + /** + * Creates new instance with no preset capabilities. + */ + public MobileOptions() { + } + + /** + * Creates new instance with provided capabilities capabilities. + * + * @param source is Capabilities instance to merge into new instance + */ + public MobileOptions(Capabilities source) { + merge(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); + } + + /** + * Get the kind of mobile device or emulator to use. + * + * @return String representing the kind of mobile device or emulator to use. + * @see org.openqa.selenium.remote.CapabilityType#PLATFORM_NAME + */ + public String getPlatformName() { + return (String) getCapability(CapabilityType.PLATFORM_NAME); + } + + /** + * 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 number of seconds to timeout 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 timeout before seeing a new command in seconds. + * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT + */ + public Duration getNewCommandTimeout() { + Object duration = getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT); + if (duration.getClass().isAssignableFrom(Long.class)) { + return Duration.ofSeconds((Long) duration); + } + Integer integer = (Integer) duration; + Long value = Long.valueOf(integer); + return Duration.ofSeconds(value); + } + + /** + * 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/test/java/io/appium/java_client/IntentExample.apk b/src/test/java/io/appium/java_client/IntentExample.apk index b86d5e9b7..196ea9094 100644 Binary files a/src/test/java/io/appium/java_client/IntentExample.apk and b/src/test/java/io/appium/java_client/IntentExample.apk differ diff --git a/src/test/java/io/appium/java_client/android/AndroidOptionsTest.java b/src/test/java/io/appium/java_client/android/AndroidOptionsTest.java new file mode 100644 index 000000000..1e4af649b --- /dev/null +++ b/src/test/java/io/appium/java_client/android/AndroidOptionsTest.java @@ -0,0 +1,305 @@ +/* + * 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; + +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.remote.MobilePlatform; +import org.junit.Test; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.ScreenOrientation; +import org.openqa.selenium.chrome.ChromeOptions; + +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +public class AndroidOptionsTest { + private AndroidMobileOptions androidMobileOptions = new AndroidMobileOptions(); + + @Test + public void setsPlatformNameByDefault() { + assertEquals(MobilePlatform.ANDROID, androidMobileOptions.getPlatformName()); + } + + @Test + public void acceptsExistingCapabilities() { + MutableCapabilities capabilities = new MutableCapabilities(); + capabilities.setCapability("deviceName", "Pixel"); + capabilities.setCapability("platformVersion", "10"); + capabilities.setCapability("newCommandTimeout", 60); + + androidMobileOptions = new AndroidMobileOptions(capabilities); + + assertEquals("Pixel", androidMobileOptions.getDeviceName()); + assertEquals("10", androidMobileOptions.getPlatformVersion()); + assertEquals(Duration.ofSeconds(60), androidMobileOptions.getNewCommandTimeout()); + } + + @Test + public void acceptsMobileCapabilities() throws MalformedURLException { + androidMobileOptions.setApp(new URL("http://example.com/myapp.apk")) + .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2) + .setPlatformVersion("10") + .setDeviceName("Pixel") + .setOtherApps("/path/to/app.apk") + .setLocale("fr_CA") + .setUdid("1ae203187fc012g") + .setOrientation(ScreenOrientation.LANDSCAPE) + .setNewCommandTimeout(Duration.ofSeconds(60)) + .setLanguage("fr"); + + assertEquals("http://example.com/myapp.apk", androidMobileOptions.getApp()); + assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, androidMobileOptions.getAutomationName()); + assertEquals("10", androidMobileOptions.getPlatformVersion()); + assertEquals("Pixel", androidMobileOptions.getDeviceName()); + assertEquals("/path/to/app.apk", androidMobileOptions.getOtherApps()); + assertEquals("fr_CA", androidMobileOptions.getLocale()); + assertEquals("1ae203187fc012g", androidMobileOptions.getUdid()); + assertEquals(ScreenOrientation.LANDSCAPE, androidMobileOptions.getOrientation()); + assertEquals(Duration.ofSeconds(60), androidMobileOptions.getNewCommandTimeout()); + assertEquals("fr", androidMobileOptions.getLanguage()); + } + + @Test + public void acceptsChromeDriverOptions() { + androidMobileOptions = new AndroidMobileOptions(); + ChromeOptions chromeOptions = new ChromeOptions(); + androidMobileOptions.setChromeOptions(chromeOptions); + + assertNotNull(androidMobileOptions.getChromeOptions()); + } + + @Test + public void setsAndroidBooleanDefaultCapabilities() { + androidMobileOptions.setAllowTestPackages() + .setAndroidNaturalOrientation() + .setAutoGrantPermissions() + .setAutoLaunch() + .setChromedriverDisableBuildCheck() + .setChromedriverUseSystemExecutable() + .setDisableAndroidWatchers() + .setDisableWindowAnimation() + .setDontStopAppOnReset() + .setEnforceAppInstall() + .setEnsureWebviewsHavePages() + .setGpsEnabled() + .setIgnoreUnimportantViews() + .setNativeWebScreenshot() + .setNoSign() + .setRecreateChromeDriverSessions() + .setResetKeyboard() + .setSkipDeviceInitialization() + .setSkipLogcatCapture() + .setSkipUnlock() + .setUseKeystore(); + + assertTrue(androidMobileOptions.doesAllowTestPackages()); + assertTrue(androidMobileOptions.isAndroidNaturalOrientation()); + assertTrue(androidMobileOptions.doesAutoGrantPermissions()); + assertTrue(androidMobileOptions.doesAutoLaunch()); + assertTrue(androidMobileOptions.doesChromedriverDisableBuildCheck()); + assertTrue(androidMobileOptions.doesChromedriverUseSystemExecutable()); + assertTrue(androidMobileOptions.doesDisableAndroidWatchers()); + assertTrue(androidMobileOptions.doesDisableWindowAnimation()); + assertTrue(androidMobileOptions.isDontStopAppOnReset()); + assertTrue(androidMobileOptions.doesEnforceAppInstall()); + assertTrue(androidMobileOptions.doesEnsureWebviewsHavePages()); + assertTrue(androidMobileOptions.isGpsEnabled()); + assertTrue(androidMobileOptions.doesIgnoreUnimportantViews()); + assertTrue(androidMobileOptions.doesNativeWebScreenshot()); + assertTrue(androidMobileOptions.isNoSign()); + assertTrue(androidMobileOptions.doesRecreateChromeDriverSessions()); + assertTrue(androidMobileOptions.doesResetKeyboard()); + assertTrue(androidMobileOptions.doesSkipDeviceInitialization()); + assertTrue(androidMobileOptions.doesSkipLogcatCapture()); + assertTrue(androidMobileOptions.doesSkipUnlock()); + assertTrue(androidMobileOptions.doesUseKeystore()); + } + + @Test + public void setsAndroidBooleanValueCapabilities() { + androidMobileOptions.setAllowTestPackages(false) + .setAndroidNaturalOrientation(false) + .setAutoGrantPermissions(false) + .setAutoLaunch(false) + .setChromedriverDisableBuildCheck(false) + .setChromedriverUseSystemExecutable(false) + .setDisableAndroidWatchers(false) + .setDisableWindowAnimation(false) + .setDontStopAppOnReset(false) + .setEnforceAppInstall(false) + .setEnsureWebviewsHavePages(false) + .setGpsEnabled(false) + .setIgnoreUnimportantViews(false) + .setIsHeadless(false) + .setNativeWebScreenshot(false) + .setNoSign(false) + .setRecreateChromeDriverSessions(false) + .setResetKeyboard(false) + .setSkipDeviceInitialization(false) + .setSkipLogcatCapture(false) + .setSkipUnlock(false) + .setUseKeystore(false); + + assertFalse(androidMobileOptions.doesAllowTestPackages()); + assertFalse(androidMobileOptions.isAndroidNaturalOrientation()); + assertFalse(androidMobileOptions.doesAutoGrantPermissions()); + assertFalse(androidMobileOptions.doesAutoLaunch()); + assertFalse(androidMobileOptions.doesChromedriverDisableBuildCheck()); + assertFalse(androidMobileOptions.doesChromedriverUseSystemExecutable()); + assertFalse(androidMobileOptions.doesDisableAndroidWatchers()); + assertFalse(androidMobileOptions.doesDisableWindowAnimation()); + assertFalse(androidMobileOptions.isDontStopAppOnReset()); + assertFalse(androidMobileOptions.doesEnforceAppInstall()); + assertFalse(androidMobileOptions.doesEnsureWebviewsHavePages()); + assertFalse(androidMobileOptions.isGpsEnabled()); + assertFalse(androidMobileOptions.doesIgnoreUnimportantViews()); + assertFalse(androidMobileOptions.isHeadless()); + assertFalse(androidMobileOptions.doesNativeWebScreenshot()); + assertFalse(androidMobileOptions.isNoSign()); + assertFalse(androidMobileOptions.doesRecreateChromeDriverSessions()); + assertFalse(androidMobileOptions.doesResetKeyboard()); + assertFalse(androidMobileOptions.doesSkipDeviceInitialization()); + assertFalse(androidMobileOptions.doesSkipLogcatCapture()); + assertFalse(androidMobileOptions.doesSkipUnlock()); + assertFalse(androidMobileOptions.doesUseKeystore()); + } + + @Test + public void setsDurationCapabilities() { + androidMobileOptions.setAdbExecTimeout(Duration.ofMillis(500)) + .setAndroidDeviceReadyTimeout(Duration.ofSeconds(5)) + .setAndroidInstallTimeout(Duration.ofSeconds(300)) + .setAppWaitDuration(Duration.ofMillis(8000)) + .setAutoWebviewTimeout(Duration.ofMillis(9000)) + .setAvdLaunchTimeout(Duration.ofMillis(10000)) + .setAvdReadyTimeout(Duration.ofMillis(11000)) + .setDeviceReadyTimeout(Duration.ofSeconds(33)); + + assertEquals(Duration.ofMillis(500), androidMobileOptions.getAdbExecTimeout()); + assertEquals(Duration.ofSeconds(5), androidMobileOptions.getAndroidDeviceReadyTimeout()); + assertEquals(Duration.ofSeconds(300), androidMobileOptions.getAndroidInstallTimeout()); + assertEquals(Duration.ofMillis(8000), androidMobileOptions.getAppWaitDuration()); + assertEquals(Duration.ofMillis(9000), androidMobileOptions.getAutoWebviewTimeout()); + assertEquals(Duration.ofMillis(10000), androidMobileOptions.getAvdLaunchTimeout()); + assertEquals(Duration.ofMillis(11000), androidMobileOptions.getAvdReadyTimeout()); + assertEquals(Duration.ofSeconds(33), androidMobileOptions.getDeviceReadyTimeout()); + } + + @Test + public void setsAndroidNumberCapabilities() { + List ports = new ArrayList<>(); + ports.add(9000); + ports.add(9005); + + androidMobileOptions.setAdbPort(1234) + .setChromedriverPort(1234) + .setChromedriverPorts(ports) + .setRemoteAppsCacheLimit(4) + .setSystemPort(8201) + .setWebviewDevtoolsPort(9543); + + assertEquals(Integer.valueOf(1234), androidMobileOptions.getAdbPort()); + assertEquals(1234, androidMobileOptions.getChromedriverPort()); + assertEquals(ports, androidMobileOptions.getChromedriverPorts()); + assertEquals(4, androidMobileOptions.getRemoteAppsCacheLimit()); + assertEquals(Integer.valueOf(8201), androidMobileOptions.getSystemPort()); + assertEquals(Integer.valueOf(9543), androidMobileOptions.getWebviewDevtoolsPort()); + } + + @Test + public void setsAndroidStringCapabilities() { + List chromedriverArgs = new ArrayList<>(); + chromedriverArgs.add("--disable-gpu"); + chromedriverArgs.add("--disable-web-security"); + + androidMobileOptions.setAndroidCoverage("com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation") + .setAndroidCoverageEndIntent("com.example.pkg.END_EMMA") + .setAndroidDeviceSocket("chrome_devtools_remote") + .setAndroidInstallPath("/sdcard/Downloads/") + .setAndroidScreenshotPath("/sdcard/screenshots/") + .setAppActivity(".MainActivity") + .setAppPackage("com.example.android.myApp") + .setAppWaitActivity("SplashActivity,OtherActivity") + .setAppWaitPackage("com.example.android.myApp") + .setAvd("api19") + .setAvdArgs("-netfast") + .setBuildToolsVersion("28.0.3") + .setChromedriverArgs(chromedriverArgs) + .setChromedriverChromeMappingFile("/abs/path/to/mapping.json") + .setChromedriverExecutable("/abs/path/to/webdriver") + .setChromedriverExecutableDir("/abs/path/to/chromedriver/directory") + .setIntentAction("android.intent.action.MAIN") + .setIntentCategory("android.intent.category.LAUNCHER") + .setIntentFlags("0x10200000") + .setKeyAlias("androiddebugkey") + .setKeyPassword("foo") + .setKeystorePassword("foo") + .setKeystorePath("/path/to.keystore") + .setLocaleScript("Cyrl") + .setNetworkSpeed("hscsd") + .setOptionalIntentArguments("--esn 2222") + .setRemoteAdbHost("192.168.0.101") + .setUninstallOtherPackages("io.appium.ex1,io.appium.ex2") + .setUnlockKey("1111") + .setUnlockType("password"); + + assertEquals("com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation", androidMobileOptions.getAndroidCoverage()); + assertEquals("com.example.pkg.END_EMMA", androidMobileOptions.getAndroidCoverageEndIntent()); + assertEquals("chrome_devtools_remote", androidMobileOptions.getAndroidDeviceSocket()); + assertEquals("/sdcard/Downloads/", androidMobileOptions.getAndroidInstallPath()); + assertEquals("/sdcard/screenshots/", androidMobileOptions.getAndroidScreenshotPath()); + assertEquals(".MainActivity", androidMobileOptions.getAppActivity()); + assertEquals("com.example.android.myApp", androidMobileOptions.getAppPackage()); + assertEquals("SplashActivity,OtherActivity", androidMobileOptions.getAppWaitActivity()); + assertEquals("com.example.android.myApp", androidMobileOptions.getAppWaitPackage()); + assertEquals("api19", androidMobileOptions.getAvd()); + assertEquals("-netfast", androidMobileOptions.getAvdArgs()); + assertEquals("28.0.3", androidMobileOptions.getBuildToolsVersion()); + assertEquals(chromedriverArgs, androidMobileOptions.getChromedriverArgs()); + assertEquals("/abs/path/to/mapping.json", androidMobileOptions.getChromedriverChromeMappingFile()); + assertEquals("/abs/path/to/webdriver", androidMobileOptions.getChromedriverExecutable()); + assertEquals("/abs/path/to/chromedriver/directory", androidMobileOptions.getChromedriverExecutableDir()); + assertEquals("android.intent.action.MAIN", androidMobileOptions.getIntentAction()); + assertEquals("android.intent.category.LAUNCHER", androidMobileOptions.getIntentCategory()); + assertEquals("0x10200000", androidMobileOptions.getIntentFlags()); + assertEquals("androiddebugkey", androidMobileOptions.getKeyAlias()); + assertEquals("foo", androidMobileOptions.getKeyPassword()); + assertEquals("foo", androidMobileOptions.getKeystorePassword()); + assertEquals("/path/to.keystore", androidMobileOptions.getKeystorePath()); + assertEquals("Cyrl", androidMobileOptions.getLocaleScript()); + assertEquals("hscsd", androidMobileOptions.getNetworkSpeed()); + assertEquals("--esn 2222", androidMobileOptions.getOptionalIntentArguments()); + assertEquals("192.168.0.101", androidMobileOptions.getRemoteAdbHost()); + assertEquals("io.appium.ex1,io.appium.ex2", androidMobileOptions.getUninstallOtherPackages()); + assertEquals("1111", androidMobileOptions.getUnlockKey()); + assertEquals("password", androidMobileOptions.getUnlockType()); + } + + @Test + public void setsAndroidEnumCapabilities() { + androidMobileOptions.setNetworkSpeed(NetworkSpeed.EVDO) + .setUnlockType(UnlockType.PASSWORD); + + assertEquals("evdo", androidMobileOptions.getNetworkSpeed()); + assertEquals("password", androidMobileOptions.getUnlockType()); + } +} diff --git a/src/test/java/io/appium/java_client/ios/IOSOptionsTest.java b/src/test/java/io/appium/java_client/ios/IOSOptionsTest.java new file mode 100644 index 000000000..dd391097d --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/IOSOptionsTest.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.ios; + +import io.appium.java_client.remote.MobilePlatform; +import org.junit.Test; +import org.openqa.selenium.MutableCapabilities; + +import java.time.Duration; + +import static org.junit.Assert.assertEquals; + +public class IOSOptionsTest { + private IOSMobileOptions iosMobileOptions = new IOSMobileOptions(); + + @Test + public void setsPlatformNameByDefault() { + assertEquals(MobilePlatform.IOS, iosMobileOptions.getPlatformName()); + } + + @Test + public void acceptsExistingCapabilities() { + MutableCapabilities capabilities = new MutableCapabilities(); + capabilities.setCapability("deviceName", "Pixel"); + capabilities.setCapability("platformVersion", "10"); + capabilities.setCapability("newCommandTimeout", 60); + + iosMobileOptions = new IOSMobileOptions(capabilities); + + assertEquals("Pixel", iosMobileOptions.getDeviceName()); + assertEquals("10", iosMobileOptions.getPlatformVersion()); + assertEquals(Duration.ofSeconds(60), iosMobileOptions.getNewCommandTimeout()); + } +} diff --git a/src/test/java/io/appium/java_client/remote/MobileOptionsTest.java b/src/test/java/io/appium/java_client/remote/MobileOptionsTest.java new file mode 100644 index 000000000..27e1a6765 --- /dev/null +++ b/src/test/java/io/appium/java_client/remote/MobileOptionsTest.java @@ -0,0 +1,109 @@ +/* + * 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; + +import org.junit.Test; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.ScreenOrientation; + +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; +import java.util.ArrayList; + +import static org.junit.Assert.*; + +public class MobileOptionsTest { + private MobileOptions mobileOptions = new MobileOptions<>(); + + @Test + public void acceptsExistingCapabilities() { + MutableCapabilities capabilities = new MutableCapabilities(); + capabilities.setCapability("deviceName", "Pixel"); + capabilities.setCapability("platformVersion", "10"); + capabilities.setCapability("newCommandTimeout", 60); + + mobileOptions = new MobileOptions<>(capabilities); + + assertEquals("Pixel", mobileOptions.getDeviceName()); + assertEquals("10", mobileOptions.getPlatformVersion()); + assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout()); + } + + @Test + public void acceptsMobileCapabilities() throws MalformedURLException { + mobileOptions.setApp(new URL("http://example.com/myapp.apk")) + .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2) + .setPlatformVersion("10") + .setDeviceName("Pixel") + .setOtherApps("/path/to/app.apk") + .setLocale("fr_CA") + .setUdid("1ae203187fc012g") + .setOrientation(ScreenOrientation.LANDSCAPE) + .setNewCommandTimeout(Duration.ofSeconds(60)) + .setLanguage("fr"); + + assertEquals("http://example.com/myapp.apk", mobileOptions.getApp()); + assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, mobileOptions.getAutomationName()); + assertEquals("10", mobileOptions.getPlatformVersion()); + assertEquals("Pixel", mobileOptions.getDeviceName()); + assertEquals("/path/to/app.apk", mobileOptions.getOtherApps()); + assertEquals("fr_CA", mobileOptions.getLocale()); + assertEquals("1ae203187fc012g", mobileOptions.getUdid()); + assertEquals(ScreenOrientation.LANDSCAPE, mobileOptions.getOrientation()); + assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout()); + assertEquals("fr", mobileOptions.getLanguage()); + } + + @Test + public void acceptsMobileBooleanCapabilityDefaults() { + mobileOptions.setClearSystemFiles() + .setAutoWebview() + .setEnablePerformanceLogging() + .setEventTimings() + .setAutoWebview() + .setFullReset() + .setPrintPageSourceOnFindFailure(); + + assertTrue(mobileOptions.doesClearSystemFiles()); + assertTrue(mobileOptions.doesAutoWebview()); + assertTrue(mobileOptions.isEnablePerformanceLogging()); + assertTrue(mobileOptions.doesEventTimings()); + assertTrue(mobileOptions.doesAutoWebview()); + assertTrue(mobileOptions.doesFullReset()); + assertTrue(mobileOptions.doesPrintPageSourceOnFindFailure()); + } + + @Test + public void setsMobileBooleanCapabilities() { + mobileOptions.setClearSystemFiles(false) + .setAutoWebview(false) + .setEnablePerformanceLogging(false) + .setEventTimings(false) + .setAutoWebview(false) + .setFullReset(false) + .setPrintPageSourceOnFindFailure(false); + + assertFalse(mobileOptions.doesClearSystemFiles()); + assertFalse(mobileOptions.doesAutoWebview()); + assertFalse(mobileOptions.isEnablePerformanceLogging()); + assertFalse(mobileOptions.doesEventTimings()); + assertFalse(mobileOptions.doesAutoWebview()); + assertFalse(mobileOptions.doesFullReset()); + assertFalse(mobileOptions.doesPrintPageSourceOnFindFailure()); + } +}