diff --git a/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java b/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java index f06086820..eab916b61 100644 --- a/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java +++ b/src/main/java/io/appium/java_client/ios/options/XCUITestOptions.java @@ -74,6 +74,25 @@ import io.appium.java_client.ios.options.wda.SupportsWdaStartupRetryIntervalOption; import io.appium.java_client.ios.options.wda.SupportsWebDriverAgentUrlOption; import io.appium.java_client.ios.options.wda.SupportsXcodeCertificateOptions; +import io.appium.java_client.ios.options.webview.SupportsAbsoluteWebLocationsOption; +import io.appium.java_client.ios.options.webview.SupportsAdditionalWebviewBundleIdsOption; +import io.appium.java_client.ios.options.webview.SupportsEnableAsyncExecuteFromHttpsOption; +import io.appium.java_client.ios.options.webview.SupportsFullContextListOption; +import io.appium.java_client.ios.options.webview.SupportsIncludeSafariInWebviewsOption; +import io.appium.java_client.ios.options.webview.SupportsNativeWebTapOption; +import io.appium.java_client.ios.options.webview.SupportsNativeWebTapStrictOption; +import io.appium.java_client.ios.options.webview.SupportsSafariAllowPopupsOption; +import io.appium.java_client.ios.options.webview.SupportsSafariGarbageCollectOption; +import io.appium.java_client.ios.options.webview.SupportsSafariIgnoreFraudWarningOption; +import io.appium.java_client.ios.options.webview.SupportsSafariIgnoreWebHostnamesOption; +import io.appium.java_client.ios.options.webview.SupportsSafariInitialUrlOption; +import io.appium.java_client.ios.options.webview.SupportsSafariLogAllCommunicationHexDumpOption; +import io.appium.java_client.ios.options.webview.SupportsSafariLogAllCommunicationOption; +import io.appium.java_client.ios.options.webview.SupportsSafariOpenLinksInBackgroundOption; +import io.appium.java_client.ios.options.webview.SupportsSafariSocketChunkSizeOption; +import io.appium.java_client.ios.options.webview.SupportsSafariWebInspectorMaxFrameLengthOption; +import io.appium.java_client.ios.options.webview.SupportsWebviewConnectRetriesOption; +import io.appium.java_client.ios.options.webview.SupportsWebviewConnectTimeoutOption; import io.appium.java_client.remote.AutomationName; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.remote.options.BaseOptions; @@ -164,9 +183,28 @@ public class XCUITestOptions extends BaseOptions implements SupportsSimulatorPasteboardAutomaticSyncOption, SupportsSimulatorDevicesSetPathOption, SupportsCustomSslCertOption, - SupportsWebkitResponseTimeoutOption, - // TODO: Web context options: https://github.com/appium/appium-xcuitest-driver#web-context + // Web context options: https://github.com/appium/appium-xcuitest-driver#web-context SupportsAutoWebViewOption, + SupportsAbsoluteWebLocationsOption, + SupportsSafariGarbageCollectOption, + SupportsIncludeSafariInWebviewsOption, + SupportsSafariLogAllCommunicationOption, + SupportsSafariLogAllCommunicationHexDumpOption, + SupportsSafariSocketChunkSizeOption, + SupportsSafariWebInspectorMaxFrameLengthOption, + SupportsAdditionalWebviewBundleIdsOption, + SupportsWebviewConnectTimeoutOption, + SupportsSafariIgnoreWebHostnamesOption, + SupportsNativeWebTapOption, + SupportsNativeWebTapStrictOption, + SupportsSafariInitialUrlOption, + SupportsSafariAllowPopupsOption, + SupportsSafariIgnoreFraudWarningOption, + SupportsSafariOpenLinksInBackgroundOption, + SupportsWebviewConnectRetriesOption, + SupportsWebkitResponseTimeoutOption, + SupportsEnableAsyncExecuteFromHttpsOption, + SupportsFullContextListOption, // TODO: Other options: https://github.com/appium/appium-xcuitest-driver#other SupportsClearSystemFilesOption, SupportsEnablePerformanceLoggingOption { diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsAbsoluteWebLocationsOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsAbsoluteWebLocationsOption.java new file mode 100644 index 000000000..ae3375b70 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsAbsoluteWebLocationsOption.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsAbsoluteWebLocationsOption> extends + Capabilities, CanSetCapability { + String ABSOLUTE_WEB_LOCATIONS_OPTION = "absoluteWebLocations"; + + /** + * Enforces Get Element Location to return coordinates + * relative to the page origin for web view elements. + * + * @return self instance for chaining. + */ + default T absoluteWebLocations() { + return amend(ABSOLUTE_WEB_LOCATIONS_OPTION, true); + } + + /** + * This capability will direct the Get Element Location command, when used + * within webviews, to return coordinates which are relative to the origin of + * the page, rather than relative to the current scroll offset. This capability + * has no effect outside of webviews. Default false. + * + * @param value Whether to return coordinates relative to the page origin for web view elements. + * @return self instance for chaining. + */ + default T setAbsoluteWebLocations(boolean value) { + return amend(ABSOLUTE_WEB_LOCATIONS_OPTION, value); + } + + /** + * Get whether Get Element Location returns coordinates + * relative to the page origin for web view elements. + * + * @return True or false. + */ + default Optional doesAbsoluteWebLocations() { + return Optional.ofNullable(toSafeBoolean(getCapability(ABSOLUTE_WEB_LOCATIONS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsAdditionalWebviewBundleIdsOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsAdditionalWebviewBundleIdsOption.java new file mode 100644 index 000000000..a21044b8f --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsAdditionalWebviewBundleIdsOption.java @@ -0,0 +1,53 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.List; +import java.util.Optional; + +public interface SupportsAdditionalWebviewBundleIdsOption> extends + Capabilities, CanSetCapability { + String ADDITIONAL_WEBVIEW_BUNDLE_IDS_OPTION = "additionalWebviewBundleIds"; + + /** + * Array of possible bundle identifiers for webviews. This is sometimes + * necessary if the Web Inspector is found to be returning a modified + * bundle identifier for the app. Defaults to []. + * + * @param identifiers Identifiers list. + * @return self instance for chaining. + */ + default T setAdditionalWebviewBundleIds(List identifiers) { + return amend(ADDITIONAL_WEBVIEW_BUNDLE_IDS_OPTION, identifiers); + } + + /** + * Get the array of possible bundle identifiers for webviews. + * + * @return Identifier list. + */ + default Optional> getAdditionalWebviewBundleIds() { + //noinspection unchecked + return Optional.ofNullable( + (List) getCapability(ADDITIONAL_WEBVIEW_BUNDLE_IDS_OPTION) + ); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsEnableAsyncExecuteFromHttpsOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsEnableAsyncExecuteFromHttpsOption.java new file mode 100644 index 000000000..36e135436 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsEnableAsyncExecuteFromHttpsOption.java @@ -0,0 +1,59 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsEnableAsyncExecuteFromHttpsOption> extends + Capabilities, CanSetCapability { + String ENABLE_ASYNC_EXECUTE_FROM_HTTPS_OPTION = "enableAsyncExecuteFromHttps"; + + /** + * Enforces to allow simulators to execute async JavaScript on pages using HTTPS. + * + * @return self instance for chaining. + */ + default T enableAsyncExecuteFromHttps() { + return amend(ENABLE_ASYNC_EXECUTE_FROM_HTTPS_OPTION, true); + } + + /** + * Capability to allow simulators to execute asynchronous JavaScript + * on pages using HTTPS. Defaults to false. + * + * @param value Whether to allow simulators to execute async JavaScript on pages using HTTPS. + * @return self instance for chaining. + */ + default T setEnableAsyncExecuteFromHttps(boolean value) { + return amend(ENABLE_ASYNC_EXECUTE_FROM_HTTPS_OPTION, value); + } + + /** + * Get whether to allow simulators to execute async JavaScript on pages using HTTPS. + * + * @return True or false. + */ + default Optional doesEnableAsyncExecuteFromHttps() { + return Optional.ofNullable(toSafeBoolean(getCapability(ENABLE_ASYNC_EXECUTE_FROM_HTTPS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsFullContextListOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsFullContextListOption.java new file mode 100644 index 000000000..da432480c --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsFullContextListOption.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsFullContextListOption> extends + Capabilities, CanSetCapability { + String FULL_CONTEXT_LIST_OPTION = "fullContextList"; + + /** + * Enforces to return the detailed information on contexts for the get available + * context command. + * + * @return self instance for chaining. + */ + default T fullContextList() { + return amend(FULL_CONTEXT_LIST_OPTION, true); + } + + /** + * Sets to return the detailed information on contexts for the get available + * context command. If this capability is enabled, then each item in the returned + * contexts list would additionally include WebView title, full URL and the bundle + * identifier. Defaults to false. + * + * @param value Whether to return the detailed info on available context command. + * @return self instance for chaining. + */ + default T setFullContextList(boolean value) { + return amend(FULL_CONTEXT_LIST_OPTION, value); + } + + /** + * Get whether to return the detailed information on contexts for the get available + * context command. + * + * @return True or false. + */ + default Optional doesFullContextList() { + return Optional.ofNullable(toSafeBoolean(getCapability(FULL_CONTEXT_LIST_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsIncludeSafariInWebviewsOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsIncludeSafariInWebviewsOption.java new file mode 100644 index 000000000..c7709050b --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsIncludeSafariInWebviewsOption.java @@ -0,0 +1,62 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsIncludeSafariInWebviewsOption> extends + Capabilities, CanSetCapability { + String INCLUDE_SAFARI_IN_WEBVIEWS_OPTION = "includeSafariInWebviews"; + + /** + * Enforces Safari web views to be added to the list of contexts available + * during a native/webview app test. + * + * @return self instance for chaining. + */ + default T includeSafariInWebviews() { + return amend(INCLUDE_SAFARI_IN_WEBVIEWS_OPTION, true); + } + + /** + * Add Safari web contexts to the list of contexts available during a + * native/webview app test. This is useful if the test opens Safari and + * needs to be able to interact with it. Defaults to false. + * + * @param value Whether to add Safari to the list of contexts available during a native/webview app test. + * @return self instance for chaining. + */ + default T setIncludeSafariInWebviews(boolean value) { + return amend(INCLUDE_SAFARI_IN_WEBVIEWS_OPTION, value); + } + + /** + * Get whether to add Safari web views to the list of contexts available + * during a native/webview app test. + * + * @return True or false. + */ + default Optional doesIncludeSafariInWebviews() { + return Optional.ofNullable(toSafeBoolean(getCapability(INCLUDE_SAFARI_IN_WEBVIEWS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsNativeWebTapOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsNativeWebTapOption.java new file mode 100644 index 000000000..5158a06f7 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsNativeWebTapOption.java @@ -0,0 +1,60 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsNativeWebTapOption> extends + Capabilities, CanSetCapability { + String NATIVE_WEB_TAP_OPTION = "nativeWebTap"; + + /** + * Enforces native non-javascript-based taps in web context mode. + * + * @return self instance for chaining. + */ + default T nativeWebTap() { + return amend(NATIVE_WEB_TAP_OPTION, true); + } + + /** + * Enable native, non-javascript-based taps being in web context mode. Defaults + * to false. Warning: sometimes the preciseness of native taps could be broken, + * because there is no reliable way to map web element coordinates to native ones. + * + * @param value Whether to enable native taps in web view mode. + * @return self instance for chaining. + */ + default T setNativeWebTap(boolean value) { + return amend(NATIVE_WEB_TAP_OPTION, value); + } + + /** + * Get whether to enable native taps in web view mode. + * + * @return True or false. + */ + default Optional doesNativeWebTap() { + return Optional.ofNullable(toSafeBoolean(getCapability(NATIVE_WEB_TAP_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsNativeWebTapStrictOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsNativeWebTapStrictOption.java new file mode 100644 index 000000000..0711d9b1f --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsNativeWebTapStrictOption.java @@ -0,0 +1,59 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsNativeWebTapStrictOption> extends + Capabilities, CanSetCapability { + String NATIVE_WEB_TAP_STRICT_OPTION = "nativeWebTapStrict"; + + /** + * Enforce native taps to be done by XCUITest driver rather than WebDriverAgent. + * + * @return self instance for chaining. + */ + default T nativeWebTapStrict() { + return amend(NATIVE_WEB_TAP_STRICT_OPTION, true); + } + + /** + * Configure native taps to be done by XCUITest driver rather than WebDriverAgent. + * Only applicable if nativeWebTap is enabled. false by default. + * + * @param value Whether native taps are done by XCUITest driver rather than WebDriverAgent. + * @return self instance for chaining. + */ + default T setNativeWebTapStrict(boolean value) { + return amend(NATIVE_WEB_TAP_STRICT_OPTION, value); + } + + /** + * Get whether native taps are done by XCUITest driver rather than WebDriverAgent. + * + * @return True or false. + */ + default Optional doesNativeWebTapStrict() { + return Optional.ofNullable(toSafeBoolean(getCapability(NATIVE_WEB_TAP_STRICT_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariAllowPopupsOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariAllowPopupsOption.java new file mode 100644 index 000000000..d7ad7d1f0 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariAllowPopupsOption.java @@ -0,0 +1,58 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsSafariAllowPopupsOption> extends + Capabilities, CanSetCapability { + String SAFARI_ALLOW_POPUPS_OPTION = "safariAllowPopups"; + + /** + * Enforces to allow javascript to open popups in Safari. + * + * @return self instance for chaining. + */ + default T safariAllowPopups() { + return amend(SAFARI_ALLOW_POPUPS_OPTION, true); + } + + /** + * Allow javascript to open new windows in Safari. Default keeps current sim setting. + * + * @param value Whether to allow javascript to open popups in Safari. + * @return self instance for chaining. + */ + default T setSafariAllowPopups(boolean value) { + return amend(SAFARI_ALLOW_POPUPS_OPTION, value); + } + + /** + * Get whether to allow javascript to open new windows in Safari. + * + * @return True or false. + */ + default Optional doesSafariAllowPopups() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_ALLOW_POPUPS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariGarbageCollectOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariGarbageCollectOption.java new file mode 100644 index 000000000..2990e2a75 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariGarbageCollectOption.java @@ -0,0 +1,59 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsSafariGarbageCollectOption> extends + Capabilities, CanSetCapability { + String SAFARI_GARBAGE_COLLECT_OPTION = "safariGarbageCollect"; + + /** + * Enforces to turn on garbage collection when executing scripts on Safari. + * + * @return self instance for chaining. + */ + default T safariGarbageCollect() { + return amend(SAFARI_GARBAGE_COLLECT_OPTION, true); + } + + /** + * Turns on/off Web Inspector garbage collection when executing scripts on Safari. + * Turning on may improve performance. Defaults to false. + * + * @param value Whether to turn on garbage collection when executing scripts on Safari. + * @return self instance for chaining. + */ + default T setSafariGarbageCollect(boolean value) { + return amend(SAFARI_GARBAGE_COLLECT_OPTION, value); + } + + /** + * Get whether to turn on garbage collection when executing scripts on Safari. + * + * @return True or false. + */ + default Optional doesSafariGarbageCollect() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_GARBAGE_COLLECT_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariIgnoreFraudWarningOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariIgnoreFraudWarningOption.java new file mode 100644 index 000000000..ad51e338a --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariIgnoreFraudWarningOption.java @@ -0,0 +1,59 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsSafariIgnoreFraudWarningOption> extends + Capabilities, CanSetCapability { + String SAFARI_IGNORE_FRAUD_WARNING_OPTION = "safariIgnoreFraudWarning"; + + /** + * Enforces to prevent Safari from showing a fraudulent website warning. + * + * @return self instance for chaining. + */ + default T safariIgnoreFraudWarning() { + return amend(SAFARI_IGNORE_FRAUD_WARNING_OPTION, true); + } + + /** + * Prevent Safari from showing a fraudulent website warning. + * Default keeps current sim setting.. + * + * @param value Whether to prevent Safari from showing a fraudulent website warning. + * @return self instance for chaining. + */ + default T setSafariIgnoreFraudWarning(boolean value) { + return amend(SAFARI_IGNORE_FRAUD_WARNING_OPTION, value); + } + + /** + * Get whether to prevent Safari from showing a fraudulent website warning. + * + * @return True or false. + */ + default Optional doesSafariIgnoreFraudWarning() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_IGNORE_FRAUD_WARNING_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariIgnoreWebHostnamesOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariIgnoreWebHostnamesOption.java new file mode 100644 index 000000000..e8e154e72 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariIgnoreWebHostnamesOption.java @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +public interface SupportsSafariIgnoreWebHostnamesOption> extends + Capabilities, CanSetCapability { + String SAFARI_IGNORE_WEB_HOSTNAMES_OPTION = "safariIgnoreWebHostnames"; + + /** + * Provide a list of hostnames (comma-separated) that the Safari automation + * tools should ignore. This is to provide a workaround to prevent a webkit + * bug where the web context is unintentionally changed to a 3rd party website + * and the test gets stuck. The common culprits are search engines (yahoo, bing, + * google) and about:blank. + * + * @param hostnames E.g. 'www.yahoo.com, www.bing.com, www.google.com, about:blank'. + * @return self instance for chaining. + */ + default T setSafariIgnoreWebHostnames(String hostnames) { + return amend(SAFARI_IGNORE_WEB_HOSTNAMES_OPTION, hostnames); + } + + /** + * Get the comma-separated list of host names to be ignored. + * + * @return XCTest result bundle path. + */ + default Optional getSafariIgnoreWebHostnames() { + return Optional.ofNullable((String) getCapability(SAFARI_IGNORE_WEB_HOSTNAMES_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariInitialUrlOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariInitialUrlOption.java new file mode 100644 index 000000000..bd2193a3e --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariInitialUrlOption.java @@ -0,0 +1,47 @@ +/* + * 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.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +public interface SupportsSafariInitialUrlOption> extends + Capabilities, CanSetCapability { + String SAFARI_INITIAL_URL_OPTION = "safariInitialUrl"; + + /** + * Set initial safari url, default is a local welcome page. + * + * @param url Initial safari url. + * @return self instance for chaining. + */ + default T setSafariInitialUrl(String url) { + return amend(SAFARI_INITIAL_URL_OPTION, url); + } + + /** + * Get the initial safari url. + * + * @return Initial safari url. + */ + default Optional getSafariInitialUrl() { + return Optional.ofNullable((String) getCapability(SAFARI_INITIAL_URL_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariLogAllCommunicationHexDumpOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariLogAllCommunicationHexDumpOption.java new file mode 100644 index 000000000..4dbece202 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariLogAllCommunicationHexDumpOption.java @@ -0,0 +1,64 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsSafariLogAllCommunicationHexDumpOption> extends + Capabilities, CanSetCapability { + String SAFARI_LOG_ALL_COMMUNICATION_HEX_DUMP_OPTION = "safariLogAllCommunicationHexDump"; + + /** + * Enforces logging of plists sent to and received from the Web Inspector + * in hex dump format. + * + * @return self instance for chaining. + */ + default T safariLogAllCommunicationHexDump() { + return amend(SAFARI_LOG_ALL_COMMUNICATION_HEX_DUMP_OPTION, true); + } + + /** + * Log all communication sent to and received from the Web Inspector, as raw + * hex dump and printable characters. This logging is done before any data + * manipulation, and so can elucidate some communication issues. Like + * appium:safariLogAllCommunication, this can produce a lot of data in some cases, + * so it is recommended to be used only when necessary. Defaults to false. + * + * @param value Whether to log all internal web debugger communication in hex dump format. + * @return self instance for chaining. + */ + default T setSafariLogAllCommunicationHexDump(boolean value) { + return amend(SAFARI_LOG_ALL_COMMUNICATION_HEX_DUMP_OPTION, value); + } + + /** + * Get whether to log of plists sent to and received from the Web Inspector + * in hex dump format. + * + * @return True or false. + */ + default Optional doesSafariLogAllCommunicationHexDump() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_LOG_ALL_COMMUNICATION_HEX_DUMP_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariLogAllCommunicationOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariLogAllCommunicationOption.java new file mode 100644 index 000000000..e351cbb62 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariLogAllCommunicationOption.java @@ -0,0 +1,60 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsSafariLogAllCommunicationOption> extends + Capabilities, CanSetCapability { + String SAFARI_LOG_ALL_COMMUNICATION_OPTION = "safariLogAllCommunication"; + + /** + * Enforces logging of plists sent to and received from the Web Inspector. + * + * @return self instance for chaining. + */ + default T safariLogAllCommunication() { + return amend(SAFARI_LOG_ALL_COMMUNICATION_OPTION, true); + } + + /** + * Log all plists sent to and received from the Web Inspector, as plain text. + * For some operations this can be a lot of data, so it is recommended to + * be used only when necessary. Defaults to false. + * + * @param value Whether to log all internal web debugger communication. + * @return self instance for chaining. + */ + default T setSafariLogAllCommunication(boolean value) { + return amend(SAFARI_LOG_ALL_COMMUNICATION_OPTION, value); + } + + /** + * Get whether to log of plists sent to and received from the Web Inspector. + * + * @return True or false. + */ + default Optional doesSafariLogAllCommunication() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_LOG_ALL_COMMUNICATION_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariOpenLinksInBackgroundOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariOpenLinksInBackgroundOption.java new file mode 100644 index 000000000..28b79a962 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariOpenLinksInBackgroundOption.java @@ -0,0 +1,59 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsSafariOpenLinksInBackgroundOption> extends + Capabilities, CanSetCapability { + String SAFARI_OPEN_LINKS_IN_BACKGROUND_OPTION = "safariOpenLinksInBackground"; + + /** + * Enforces Safari to open links in new windows. + * + * @return self instance for chaining. + */ + default T safariOpenLinksInBackground() { + return amend(SAFARI_OPEN_LINKS_IN_BACKGROUND_OPTION, true); + } + + /** + * Whether Safari should allow links to open in new windows. + * Default keeps current sim setting. + * + * @param value Whether Safari should allow links to open in new windows. + * @return self instance for chaining. + */ + default T setSafariOpenLinksInBackground(boolean value) { + return amend(SAFARI_OPEN_LINKS_IN_BACKGROUND_OPTION, value); + } + + /** + * Get whether Safari should allow links to open in new windows. + * + * @return True or false. + */ + default Optional doesSafariOpenLinksInBackground() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_OPEN_LINKS_IN_BACKGROUND_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariSocketChunkSizeOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariSocketChunkSizeOption.java new file mode 100644 index 000000000..24190efaa --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariSocketChunkSizeOption.java @@ -0,0 +1,52 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toInteger; + +public interface SupportsSafariSocketChunkSizeOption> extends + Capabilities, CanSetCapability { + String SAFARI_SOCKET_CHUNK_SIZE_OPTION = "safariSocketChunkSize"; + + /** + * The size, in bytes, of the data to be sent to the Web Inspector on + * iOS 11+ real devices. Some devices hang when sending large amounts of + * data to the Web Inspector, and breaking them into smaller parts can be + * helpful in those cases. Defaults to 16384 (also the maximum possible). + * + * @param size Socket chunk size in range 1..16384. + * @return self instance for chaining. + */ + default T setSafariSocketChunkSize(int size) { + return amend(SAFARI_SOCKET_CHUNK_SIZE_OPTION, size); + } + + /** + * Get the size of a single remote debugger socket chunk. + * + * @return Chunk size in bytes. + */ + default Optional getSafariSocketChunkSize() { + return Optional.ofNullable(toInteger(getCapability(SAFARI_SOCKET_CHUNK_SIZE_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariWebInspectorMaxFrameLengthOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariWebInspectorMaxFrameLengthOption.java new file mode 100644 index 000000000..b3b4c6f26 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsSafariWebInspectorMaxFrameLengthOption.java @@ -0,0 +1,52 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toInteger; + +public interface SupportsSafariWebInspectorMaxFrameLengthOption> extends + Capabilities, CanSetCapability { + String SAFARI_WEB_INSPECTOR_MAX_FRAME_LENGTH_OPTION = "safariWebInspectorMaxFrameLength"; + + /** + * The maximum size in bytes of a single data frame for the Web Inspector. + * Too high values could introduce slowness and/or memory leaks. + * Too low values could introduce possible buffer overflow exceptions. + * Defaults to 20MB (20*1024*1024). + * + * @param length Max size of a single data frame. + * @return self instance for chaining. + */ + default T setSafariWebInspectorMaxFrameLength(int length) { + return amend(SAFARI_WEB_INSPECTOR_MAX_FRAME_LENGTH_OPTION, length); + } + + /** + * Get the maximum size in bytes of a single data frame for the Web Inspector. + * + * @return Size in bytes. + */ + default Optional getSafariWebInspectorMaxFrameLength() { + return Optional.ofNullable(toInteger(getCapability(SAFARI_WEB_INSPECTOR_MAX_FRAME_LENGTH_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebkitResponseTimeoutOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebkitResponseTimeoutOption.java new file mode 100644 index 000000000..dc9378399 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebkitResponseTimeoutOption.java @@ -0,0 +1,52 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.internal.CapabilityHelpers; +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.time.Duration; +import java.util.Optional; + +public interface SupportsWebkitResponseTimeoutOption> extends + Capabilities, CanSetCapability { + String WEBKIT_RESPONSE_TIMEOUT_OPTION = "webkitResponseTimeout"; + + /** + * (Real device only) Set the time to wait for a response from WebKit in + * a Safari session. Defaults to 5000ms. + * + * @param timeout Timeout to wait for a response from WebKit in a Safari session. + * @return self instance for chaining. + */ + default T setWebviewConnectTimeout(Duration timeout) { + return amend(WEBKIT_RESPONSE_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the timeout to wait for a response from WebKit in a Safari session. + * + * @return Timeout value. + */ + default Optional getWebviewConnectTimeout() { + return Optional.ofNullable( + CapabilityHelpers.toDuration(getCapability(WEBKIT_RESPONSE_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebviewConnectRetriesOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebviewConnectRetriesOption.java new file mode 100644 index 000000000..a1b658945 --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebviewConnectRetriesOption.java @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toInteger; + +public interface SupportsWebviewConnectRetriesOption> extends + Capabilities, CanSetCapability { + String WEBVIEW_CONNECT_RETRIES_OPTION = "webviewConnectRetries"; + + /** + * Number of times to send connection message to remote debugger, + * to get a webview. Default: 8. + * + * @param retries Max retries count. + * @return self instance for chaining. + */ + default T setWebviewConnectRetries(int retries) { + return amend(WEBVIEW_CONNECT_RETRIES_OPTION, retries); + } + + /** + * Get the number of retries to send connection message to remote debugger, + * to get a webview. + * + * @return Max retries count. + */ + default Optional getWebviewConnectRetries() { + return Optional.ofNullable(toInteger(getCapability(WEBVIEW_CONNECT_RETRIES_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebviewConnectTimeoutOption.java b/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebviewConnectTimeoutOption.java new file mode 100644 index 000000000..cd00db23f --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/options/webview/SupportsWebviewConnectTimeoutOption.java @@ -0,0 +1,52 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.ios.options.webview; + +import io.appium.java_client.internal.CapabilityHelpers; +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.time.Duration; +import java.util.Optional; + +public interface SupportsWebviewConnectTimeoutOption> extends + Capabilities, CanSetCapability { + String WEBVIEW_CONNECT_TIMEOUT_OPTION = "webviewConnectTimeout"; + + /** + * The time to wait for the initial presence of webviews in + * MobileSafari or hybrid apps. Defaults to 0ms. + * + * @param timeout Timeout to wait for the initial presence of webviews. + * @return self instance for chaining. + */ + default T setWebviewConnectTimeout(Duration timeout) { + return amend(WEBVIEW_CONNECT_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the timeout to wait for the initial presence of webviews. + * + * @return Timeout value. + */ + default Optional getWebviewConnectTimeout() { + return Optional.ofNullable( + CapabilityHelpers.toDuration(getCapability(WEBVIEW_CONNECT_TIMEOUT_OPTION)) + ); + } +}