From 2c2141ec985bc30ef3d69102b115abf7195ffcde Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 2 Apr 2020 20:52:13 -0500 Subject: [PATCH 1/3] feat: create android and ios driver option classes --- .../java_client/android/AndroidOptions.java | 32 +++ .../io/appium/java_client/ios/IOSOptions.java | 32 +++ .../remote/MobileCapabilityType.java | 2 +- .../java_client/remote/MobileOptions.java | 223 ++++++++++++++++++ 4 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/appium/java_client/android/AndroidOptions.java create mode 100644 src/main/java/io/appium/java_client/ios/IOSOptions.java create mode 100644 src/main/java/io/appium/java_client/remote/MobileOptions.java diff --git a/src/main/java/io/appium/java_client/android/AndroidOptions.java b/src/main/java/io/appium/java_client/android/AndroidOptions.java new file mode 100644 index 000000000..768bf75eb --- /dev/null +++ b/src/main/java/io/appium/java_client/android/AndroidOptions.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.android; + +import io.appium.java_client.remote.MobileOptions; +import io.appium.java_client.remote.MobilePlatform; +import org.openqa.selenium.Capabilities; + +public class AndroidOptions extends MobileOptions { + public AndroidOptions() { + setPlatformName(MobilePlatform.ANDROID); + } + + public AndroidOptions(Capabilities source) { + this(); + merge(source); + } +} diff --git a/src/main/java/io/appium/java_client/ios/IOSOptions.java b/src/main/java/io/appium/java_client/ios/IOSOptions.java new file mode 100644 index 000000000..14af6aad6 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/IOSOptions.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 IOSOptions extends MobileOptions { + public IOSOptions() { + setPlatformName(MobilePlatform.IOS); + } + + public IOSOptions(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 b503b3762..1f4eb00f1 100644 --- a/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java @@ -120,7 +120,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..3fa20f019 --- /dev/null +++ b/src/main/java/io/appium/java_client/remote/MobileOptions.java @@ -0,0 +1,223 @@ +/* + * 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; + +public class MobileOptions> extends MutableCapabilities { + + public MobileOptions() { + } + + public MobileOptions(Capabilities source) { + merge(source); + } + + public T setPlatformName(String platform) { + return amend(CapabilityType.PLATFORM_NAME, platform); + } + + public String getPlatformName() { + return (String) getCapability(CapabilityType.PLATFORM_NAME); + } + + public T setApp(String path) { + return amend(MobileCapabilityType.APP, path); + } + + public T setApp(URL url) { + return setApp(url.toString()); + } + + public String getApp() { + return (String) getCapability(MobileCapabilityType.APP); + } + + public T setAutomationName(String name) { + return amend(MobileCapabilityType.AUTOMATION_NAME, name); + } + + public String getAutomationName() { + return (String) getCapability(MobileCapabilityType.AUTOMATION_NAME); + } + + public T setAutoWebview() { + return setAutoWebview(true); + } + + public T setAutoWebview(boolean bool) { + return amend(MobileCapabilityType.AUTO_WEBVIEW, bool); + } + + public boolean doesAutoWebview() { + return (boolean) getCapability(MobileCapabilityType.AUTO_WEBVIEW); + } + + public T setClearSystemFiles() { + return setClearSystemFiles(true); + } + + public T setClearSystemFiles(boolean bool) { + return amend(MobileCapabilityType.CLEAR_SYSTEM_FILES, bool); + } + + public boolean doesClearSystemFiles() { + return (boolean) getCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES); + } + + public T setDeviceName(String deviceName) { + return amend(MobileCapabilityType.DEVICE_NAME, deviceName); + } + + public String getDeviceName() { + return (String) getCapability(MobileCapabilityType.DEVICE_NAME); + } + + public T setEnablePerformanceLogging() { + return setEnablePerformanceLogging(true); + } + + public T setEnablePerformanceLogging(boolean bool) { + return amend(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING, bool); + } + + public boolean isEnablePerformanceLogging() { + return (boolean) getCapability(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING); + } + + public T setEventTimings() { + return setEventTimings(true); + } + + public T setEventTimings(boolean bool) { + return amend(MobileCapabilityType.EVENT_TIMINGS, bool); + } + + public boolean doesEventTimings() { + return (boolean) getCapability(MobileCapabilityType.EVENT_TIMINGS); + } + + public T setFullReset() { + return setFullReset(true); + } + + public T setFullReset(boolean bool) { + return amend(MobileCapabilityType.FULL_RESET, bool); + } + + public boolean doesFullReset() { + return (boolean) getCapability(MobileCapabilityType.FULL_RESET); + } + + public T setLanguage(String language) { + return amend(MobileCapabilityType.LANGUAGE, language); + } + + public String getLanguage() { + return (String) getCapability(MobileCapabilityType.LANGUAGE); + } + + public T setLocale(String locale) { + return amend(MobileCapabilityType.LOCALE, locale); + } + + public String getLocale() { + return (String) getCapability(MobileCapabilityType.LOCALE); + } + + public T setNewCommandTimeout(Duration duration) { + return amend(MobileCapabilityType.NEW_COMMAND_TIMEOUT, duration.getSeconds()); + } + + public Duration getNewCommandTimeout() { + Object duration = getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT); + return Duration.ofSeconds(Long.parseLong("" + duration)); + } + + public T setNoReset() { + return setNoReset(true); + } + + public T setNoReset(boolean bool) { + return amend(MobileCapabilityType.NO_RESET, bool); + } + + public boolean doesNoReset() { + return (boolean) getCapability(MobileCapabilityType.NO_RESET); + } + + public T setOrientation(ScreenOrientation orientation) { + return amend(MobileCapabilityType.ORIENTATION, orientation); + } + + public ScreenOrientation getOrientation() { + return (ScreenOrientation) getCapability(MobileCapabilityType.ORIENTATION); + } + + public T setOtherApps(String apps) { + return amend(MobileCapabilityType.OTHER_APPS, apps); + } + + public String getOtherApps() { + return (String) getCapability(MobileCapabilityType.OTHER_APPS); + } + + public T setPlatformVersion(String version) { + return amend(MobileCapabilityType.PLATFORM_VERSION, version); + } + + public String getPlatformVersion() { + return (String) getCapability(MobileCapabilityType.PLATFORM_VERSION); + } + + public T setPrintPageSourceOnFindFailure() { + return setPrintPageSourceOnFindFailure(true); + } + + public T setPrintPageSourceOnFindFailure(boolean bool) { + return amend(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE, bool); + } + + public boolean doesPrintPageSourceOnFindFailure() { + return (boolean) getCapability(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE); + } + + public T setUdid(String id) { + return amend(MobileCapabilityType.UDID, id); + } + + 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; + } +} From 6316f4f89750a1adfc734fa2f218b7763bd2e681 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 2 Apr 2020 20:53:00 -0500 Subject: [PATCH 2/3] test: implement tests for driver options --- .../io/appium/java_client/IntentExample.apk | Bin 39857 -> 50008 bytes .../android/AndroidOptionsTest.java | 77 +++++++++++++ .../java_client/ios/IOSOptionsTest.java | 77 +++++++++++++ .../java_client/remote/MobileOptionsTest.java | 109 ++++++++++++++++++ 4 files changed, 263 insertions(+) create mode 100644 src/test/java/io/appium/java_client/android/AndroidOptionsTest.java create mode 100644 src/test/java/io/appium/java_client/ios/IOSOptionsTest.java create mode 100644 src/test/java/io/appium/java_client/remote/MobileOptionsTest.java diff --git a/src/test/java/io/appium/java_client/IntentExample.apk b/src/test/java/io/appium/java_client/IntentExample.apk index b86d5e9b7857d5f3d2eeb75ff53d46116fded082..196ea90940af607535d0cf5c57e0c22c1d3e4af2 100644 GIT binary patch delta 7085 zcmc(k2Uru!+Q$<@uTrFnB2|%+(4}|jAP^O?P^HD7bZHCdK`DY5x`=>Emky$oK`vZ!=Rd!hDSS@U7Yt!F(uEK+fyl|p zK^|p0$_hF(?OZ4z$KkQ5?%Fv!K$)!E&}+SXOX(#6#p zRP0PDPf7#^p}=I^#qHGTB47v#mdFhOfk4G^a)XS7Xh0&*muS2pku;@Pwo&XI3J^$- zsrX57J_SJd^p`Jh-KF-gCVW|ekd={8SYN|bMOf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wT(j`$whrJ6kKMWv2C2~~vf7a$bn|sl`Wp%FD?JFcu3jWmN=Ju{6~r!s@zd{S zvC0V0S9l@qQ##ssFMVuD`V7rt zZk(ZchSDlMT5*1SioE1%T?dEZUuKttHF-=DVcM5a>%nkl=g9-^deaW1GSXBqjeQEf z6hL@mTh9Y!vQ&^>-n#T>F@o)OoOwBz_+n0Nb=8iR){+C+V{VoMkXxmiJ{ShLI%q}y^d(MtFu`%c4ooBJ~b%|zhx z9rVLGS5ku5;=)d2J#s6JB#o!$U)%soT3DXb4ZsTXvq@U3&4R_%cwJ~FNjGy>`4J#)I_OTQFJa+C)yKP-z|~jY#o0`#A--ef z9Vl@QntNeMU5T^xZoFf}#rUvZD6yhb{EB;-0&RG>5wGHQQ5|zHz`bH1t9SF+tZ31e zfs9*F=gKr6M7MNF2$f==AQDL53Mpn#nqA83rq9?8r%k>la@R^&fX}fQ3298XN2}%x zCjCRh>3MIOH=mzQIhZhXaPQ%cYg>bFW-@rU_7k4?k@^{9D58If990fN)Zd~`nhzxw zKRX8QL5e2bx;r}HYqVbT;zXHxQe>NmtNi7UEZ>Fkt6J_aEiSe&-1pK|l*huV=Qz`8 z)uOiR4=ep4S`?2F@owA@oy?E4vTn}CowW^?h@Mg`xE-76=A0=b`#73SXNA?6tvEew zC?-1luO4fY?^c}W(J8u13@$bNMHOTXp7$8c%Kc+Hx^eNGPo@FilL@i8ptOVe+Y zK9xYS#(g&%u*#;0sQ9(Ps*5vs^1B_&gM4VhoabuizBV0G{#S!pB2hhbF-tdpd~kv1 zz|nNz@Hy=+*_YXry`ZrIsBvSh-^g)j{Ig`cME9v-J!$pHyLGO?V~t)N=E!S<* zrB-RhzgC8yhtJN+@WW7dNE&T2L@sWr?Oo!p^q=KxXCnQu-%@^^PiVwHtG`42j&w)j eei%>ce^+k{9vZ>NFR_y&vVD$j3nrGl(); + + @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()); + } +} From fac396ae9fdd7f0c4475435fe6d18da7a2724dc5 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Thu, 2 Apr 2020 20:53:25 -0500 Subject: [PATCH 3/3] docs: clarify methods and link to respective capability type for driver options --- .../java_client/remote/MobileOptions.java | 292 ++++++++++++++++++ 1 file changed, 292 insertions(+) diff --git a/src/main/java/io/appium/java_client/remote/MobileOptions.java b/src/main/java/io/appium/java_client/remote/MobileOptions.java index 3fa20f019..6a7810f1a 100644 --- a/src/main/java/io/appium/java_client/remote/MobileOptions.java +++ b/src/main/java/io/appium/java_client/remote/MobileOptions.java @@ -26,186 +26,478 @@ 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 allowed time before seeing a new command. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT + */ public T setNewCommandTimeout(Duration duration) { return amend(MobileCapabilityType.NEW_COMMAND_TIMEOUT, duration.getSeconds()); } + /** + * Get the timeout for new commands. + * + * @return allowed time before seeing a new command. + * @see MobileCapabilityType#NEW_COMMAND_TIMEOUT + */ public Duration getNewCommandTimeout() { Object duration = getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT); return Duration.ofSeconds(Long.parseLong("" + duration)); } + /** + * Set the app not to do a reset. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#NO_RESET + */ public T setNoReset() { return setNoReset(true); } + /** + * Set whether the app does not do a reset. + * + * @param bool is whether the app does not do a reset. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#NO_RESET + */ public T setNoReset(boolean bool) { return amend(MobileCapabilityType.NO_RESET, bool); } + /** + * Get whether the app does not do a reset. + * + * @return true if the app does not do a reset. + * @see MobileCapabilityType#NO_RESET + */ public boolean doesNoReset() { return (boolean) getCapability(MobileCapabilityType.NO_RESET); } + /** + * Set the orientation of the screen. + * + * @param orientation is the screen orientation. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#ORIENTATION + */ public T setOrientation(ScreenOrientation orientation) { return amend(MobileCapabilityType.ORIENTATION, orientation); } + /** + * Get the orientation of the screen. + * + * @return ScreenOrientation of the app. + * @see MobileCapabilityType#ORIENTATION + */ public ScreenOrientation getOrientation() { return (ScreenOrientation) getCapability(MobileCapabilityType.ORIENTATION); } + /** + * Set the location of the app(s) to install before running a test. + * + * @param apps is the apps to install. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#OTHER_APPS + */ public T setOtherApps(String apps) { return amend(MobileCapabilityType.OTHER_APPS, apps); } + /** + * Get the list of apps to install before running a test. + * + * @return String of apps to install. + * @see MobileCapabilityType#OTHER_APPS + */ public String getOtherApps() { return (String) getCapability(MobileCapabilityType.OTHER_APPS); } + /** + * Set the version of the platform. + * + * @param version is the platform version. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#PLATFORM_VERSION + */ public T setPlatformVersion(String version) { return amend(MobileCapabilityType.PLATFORM_VERSION, version); } + /** + * Get the version of the platform. + * + * @return String representing the platform version. + * @see MobileCapabilityType#PLATFORM_VERSION + */ public String getPlatformVersion() { return (String) getCapability(MobileCapabilityType.PLATFORM_VERSION); } + /** + * Set the app to print page source when a find operation fails. + * + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE + */ public T setPrintPageSourceOnFindFailure() { return setPrintPageSourceOnFindFailure(true); } + /** + * Set whether the app to print page source when a find operation fails. + * + * @param bool is whether to print page source. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE + */ public T setPrintPageSourceOnFindFailure(boolean bool) { return amend(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE, bool); } + /** + * Get whether the app to print page source when a find operation fails. + * + * @return true if app prints page source. + * @see MobileCapabilityType#PRINT_PAGE_SOURCE_ON_FIND_FAILURE + */ public boolean doesPrintPageSourceOnFindFailure() { return (boolean) getCapability(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE); } + /** + * Set the id of the device. + * + * @param id is the unique device identifier. + * @return this MobileOptions, for chaining. + * @see MobileCapabilityType#UDID + */ public T setUdid(String id) { return amend(MobileCapabilityType.UDID, id); } + /** + * Get the id of the device. + * + * @return String representing the unique device identifier. + * @see MobileCapabilityType#UDID + */ public String getUdid() { return (String) getCapability(MobileCapabilityType.UDID); }