From 0970899448b1bda9a8554531da8b6c61c0e02b3a Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 1 Nov 2021 12:43:17 +0100 Subject: [PATCH 1/2] feat: Add Safari driver options --- .../java_client/safari/SafariDriver.java | 87 +++++++++++++++++++ .../safari/options/SafariOptions.java | 71 +++++++++++++++ ...pportsSafariAutomaticInspectionOption.java | 61 +++++++++++++ ...upportsSafariAutomaticProfilingOption.java | 61 +++++++++++++ .../SupportsSafariDeviceNameOption.java | 52 +++++++++++ .../SupportsSafariDeviceTypeOption.java | 50 +++++++++++ .../SupportsSafariDeviceUdidOption.java | 52 +++++++++++ ...portsSafariPlatformBuildVersionOption.java | 50 +++++++++++ .../SupportsSafariPlatformVersionOption.java | 50 +++++++++++ .../SupportsSafariUseSimulatorOption.java | 61 +++++++++++++ .../options/SupportsWebkitWebrtcOption.java | 51 +++++++++++ .../safari/options/WebrtcData.java | 77 ++++++++++++++++ .../drivers/options/OptionsBuildingTest.java | 40 +++++++++ 13 files changed, 763 insertions(+) create mode 100644 src/main/java/io/appium/java_client/safari/SafariDriver.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SafariOptions.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceNameOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceTypeOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceUdidOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformBuildVersionOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformVersionOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsSafariUseSimulatorOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/SupportsWebkitWebrtcOption.java create mode 100644 src/main/java/io/appium/java_client/safari/options/WebrtcData.java diff --git a/src/main/java/io/appium/java_client/safari/SafariDriver.java b/src/main/java/io/appium/java_client/safari/SafariDriver.java new file mode 100644 index 000000000..c32d36b05 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/SafariDriver.java @@ -0,0 +1,87 @@ +/* + * 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.safari; + +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServiceBuilder; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.HttpCommandExecutor; +import org.openqa.selenium.remote.http.HttpClient; + +import java.net.URL; + +/** + * GeckoDriver is an officially supported Appium driver + * created to automate mobile Safari browser. The driver uses W3C + * WebDriver protocol and is built on top of Apple's safaridriver + * server. Read https://github.com/appium/appium-safari-driver + * for more details on how to configure and use it. + * + * @since Appium 1.20.0 + */ +public class SafariDriver extends AppiumDriver { + private static final String PLATFORM_NAME = Platform.IOS.toString(); + private static final String AUTOMATION_NAME = AutomationName.SAFARI; + + public SafariDriver(HttpCommandExecutor executor, Capabilities capabilities) { + super(executor, ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(URL remoteAddress, Capabilities capabilities) { + super(remoteAddress, ensurePlatformAndAutomationNames( + capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) { + super(remoteAddress, httpClientFactory, ensurePlatformAndAutomationNames( + capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(AppiumDriverLocalService service, Capabilities capabilities) { + super(service, ensurePlatformAndAutomationNames( + capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, + Capabilities capabilities) { + super(service, httpClientFactory, ensurePlatformAndAutomationNames( + capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(AppiumServiceBuilder builder, Capabilities capabilities) { + super(builder, ensurePlatformAndAutomationNames( + capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, + Capabilities capabilities) { + super(builder, httpClientFactory, ensurePlatformAndAutomationNames( + capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) { + super(httpClientFactory, ensurePlatformAndAutomationNames( + capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } + + public SafariDriver(Capabilities capabilities) { + super(ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME)); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SafariOptions.java b/src/main/java/io/appium/java_client/safari/options/SafariOptions.java new file mode 100644 index 000000000..fa170587b --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SafariOptions.java @@ -0,0 +1,71 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.safari.options; + +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.SupportsAcceptInsecureCertsOption; +import io.appium.java_client.remote.options.SupportsBrowserNameOption; +import io.appium.java_client.remote.options.SupportsBrowserVersionOption; +import io.appium.java_client.remote.options.SupportsPageLoadStrategyOption; +import io.appium.java_client.remote.options.SupportsProxyOption; +import io.appium.java_client.remote.options.SupportsSetWindowRectOption; +import io.appium.java_client.remote.options.SupportsUnhandledPromptBehaviorOption; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.Platform; + +import java.util.Map; + +/** + * https://github.com/appium/appium-safari-driver#usage + */ +public class SafariOptions extends BaseOptions implements + SupportsBrowserNameOption, + SupportsBrowserVersionOption, + SupportsSafariPlatformVersionOption, + SupportsSafariPlatformBuildVersionOption, + SupportsSafariUseSimulatorOption, + SupportsSafariDeviceTypeOption, + SupportsSafariDeviceNameOption, + SupportsSafariDeviceUdidOption, + SupportsSafariAutomaticInspectionOption, + SupportsSafariAutomaticProfilingOption, + SupportsWebkitWebrtcOption, + SupportsAcceptInsecureCertsOption, + SupportsPageLoadStrategyOption, + SupportsSetWindowRectOption, + SupportsProxyOption, + SupportsUnhandledPromptBehaviorOption { + public SafariOptions() { + setCommonOptions(); + } + + public SafariOptions(Capabilities source) { + super(source); + setCommonOptions(); + } + + public SafariOptions(Map source) { + super(source); + setCommonOptions(); + } + + private void setCommonOptions() { + setPlatformName(Platform.IOS.toString()); + setAutomationName(AutomationName.SAFARI); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java new file mode 100644 index 000000000..04be44358 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java @@ -0,0 +1,61 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.safari.options; + +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 SupportsSafariAutomaticInspectionOption> extends + Capabilities, CanSetCapability { + String SAFARI_AUTOMATIC_INSPECTION_OPTION = "safari:automaticInspection"; + + /** + * Enforces safaridriver to use Automatic Inspection. + * + * @return self instance for chaining. + */ + default T safariAutomaticInspection() { + return amend(SAFARI_AUTOMATIC_INSPECTION_OPTION, true); + } + + /** + * This capability instructs Safari to preload the Web Inspector and JavaScript + * debugger in the background prior to returning a newly-created window. + * To pause the test's execution in JavaScript and bring up Web Inspector's + * Debugger tab, you can simply evaluate a debugger; statement in the test page. + * + * @param bool Whether to use automatic inspection. + * @return self instance for chaining. + */ + default T setSafariAutomaticInspection(boolean bool) { + return amend(SAFARI_AUTOMATIC_INSPECTION_OPTION, bool); + } + + /** + * Get whether to use automatic inspection. + * + * @return true or false. + */ + default Optional doesAafariAutomaticInspection() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_INSPECTION_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java new file mode 100644 index 000000000..64a81ac29 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java @@ -0,0 +1,61 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.safari.options; + +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 SupportsSafariAutomaticProfilingOption> extends + Capabilities, CanSetCapability { + String SAFARI_AUTOMATIC_PROFILING_OPTION = "safari:automaticProfiling"; + + /** + * Enforces safaridriver to use Automatic Inspection. + * + * @return self instance for chaining. + */ + default T safariAutomaticProfiling() { + return amend(SAFARI_AUTOMATIC_PROFILING_OPTION, true); + } + + /** + * This capability instructs Safari to preload the Web Inspector and start + * a Timeline recording in the background prior to returning a newly-created + * window. To view the recording, open the Web Inspector through Safari's + * Develop menu. + * + * @param bool Whether to use automatic profiling. + * @return self instance for chaining. + */ + default T setSafariAutomaticProfiling(boolean bool) { + return amend(SAFARI_AUTOMATIC_PROFILING_OPTION, bool); + } + + /** + * Get whether to use automatic profiling. + * + * @return true or false. + */ + default Optional doesAafariAutomaticProfiling() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_PROFILING_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceNameOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceNameOption.java new file mode 100644 index 000000000..4e814d01f --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceNameOption.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.safari.options; + +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 SupportsSafariDeviceNameOption> extends + Capabilities, CanSetCapability { + String SAFARI_DEVICE_NAME_OPTION = "safari:deviceName"; + + /** + * safaridriver will only create a session using hosts whose device name + * matches the value of safari:deviceName. Device names are compared + * case-insensitively. NOTE: Device names for connected devices are shown in + * iTunes. If Xcode is installed, device names for connected devices are available + * via the output of instruments(1) and in the Devices and Simulators window + * (accessed in Xcode via "Window -> Devices and Simulators"). + * + * @param deviceName Device name. + * @return self instance for chaining. + */ + default T setSafariDeviceName(String deviceName) { + return amend(SAFARI_DEVICE_NAME_OPTION, deviceName); + } + + /** + * Get the name of the device. + * + * @return String representing the name of the device. + */ + default Optional getSafariDeviceName() { + return Optional.ofNullable((String) getCapability(SAFARI_DEVICE_NAME_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceTypeOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceTypeOption.java new file mode 100644 index 000000000..12179de61 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceTypeOption.java @@ -0,0 +1,50 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.safari.options; + +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 SupportsSafariDeviceTypeOption> extends + Capabilities, CanSetCapability { + String SAFARI_DEVICE_TYPE_OPTION = "safari:deviceType"; + + /** + * If the value of safari:deviceType is 'iPhone', safaridriver will only create a session + * using an iPhone device or iPhone simulator. If the value of safari:deviceType is 'iPad', + * safaridriver will only create a session using an iPad device or iPad simulator. + * Values of safari:deviceType are compared case-insensitively. + * + * @param deviceType Device type name. + * @return self instance for chaining. + */ + default T setSafariDeviceType(String deviceType) { + return amend(SAFARI_DEVICE_TYPE_OPTION, deviceType); + } + + /** + * Get the type of the device. + * + * @return String representing the type of the device. + */ + default Optional getSafariDeviceType() { + return Optional.ofNullable((String) getCapability(SAFARI_DEVICE_TYPE_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceUdidOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceUdidOption.java new file mode 100644 index 000000000..80ae57856 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceUdidOption.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.safari.options; + +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 SupportsSafariDeviceUdidOption> extends + Capabilities, CanSetCapability { + String SAFARI_DEVICE_UDID_OPTION = "safari:deviceUdid"; + + /** + * safaridriver will only create a session using hosts whose device UDID + * matches the value of safari:deviceUDID. Device UDIDs are compared + * case-insensitively. NOTE: If Xcode is installed, UDIDs for connected + * devices are available via the output of instruments(1) and in the + * Devices and Simulators window (accessed in Xcode via + * "Window -> Devices and Simulators"). + * + * @param deviceUdid Device UDID. + * @return self instance for chaining. + */ + default T setSafariDeviceUdid(String deviceUdid) { + return amend(SAFARI_DEVICE_UDID_OPTION, deviceUdid); + } + + /** + * Get the UDID of the device. + * + * @return String representing the UDID of the device. + */ + default Optional getSafariDeviceUdid() { + return Optional.ofNullable((String) getCapability(SAFARI_DEVICE_UDID_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformBuildVersionOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformBuildVersionOption.java new file mode 100644 index 000000000..d73993fe5 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformBuildVersionOption.java @@ -0,0 +1,50 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.safari.options; + +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 SupportsSafariPlatformBuildVersionOption> extends + Capabilities, CanSetCapability { + String SAFARI_PLATFORM_BUILD_VERSION_OPTION = "safari:platformBuildVersion"; + + /** + * safaridriver will only create a session using hosts whose OS build + * version matches the value of safari:platformBuildVersion. Example + * of a macOS build version is '18E193'. On macOS, the OS build version + * can be determined by running the sw_vers(1) utility. + * + * @param version is the platform build version. + * @return self instance for chaining. + */ + default T setSafariPlatformBuildVersion(String version) { + return amend(SAFARI_PLATFORM_BUILD_VERSION_OPTION, version); + } + + /** + * Get the build version of the platform. + * + * @return String representing the platform build version. + */ + default Optional getSafariPlatformBuildVersion() { + return Optional.ofNullable((String) getCapability(SAFARI_PLATFORM_BUILD_VERSION_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformVersionOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformVersionOption.java new file mode 100644 index 000000000..f6800b310 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariPlatformVersionOption.java @@ -0,0 +1,50 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.safari.options; + +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 SupportsSafariPlatformVersionOption> extends + Capabilities, CanSetCapability { + String SAFARI_PLATFORM_VERSION_OPTION = "safari:platformVersion"; + + /** + * safaridriver will only create a session using hosts whose OS + * version matches the value of safari:platformVersion. OS version + * numbers are prefix-matched. For example, if the value of safari:platformVersion + * is '12', this will allow hosts with an OS version of '12.0' or '12.1' but not '10.12'. + * + * @param version is the platform version. + * @return self instance for chaining. + */ + default T setSafariPlatformVersion(String version) { + return amend(SAFARI_PLATFORM_VERSION_OPTION, version); + } + + /** + * Get the version of the platform. + * + * @return String representing the platform version. + */ + default Optional getSafariPlatformVersion() { + return Optional.ofNullable((String) getCapability(SAFARI_PLATFORM_VERSION_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariUseSimulatorOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariUseSimulatorOption.java new file mode 100644 index 000000000..948ef0a45 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariUseSimulatorOption.java @@ -0,0 +1,61 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.safari.options; + +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 SupportsSafariUseSimulatorOption> extends + Capabilities, CanSetCapability { + String SAFARI_USE_SIMULATOR_OPTION = "safari:useSimulator"; + + /** + * Enforces safaridriver to use iOS Simulator. + * + * @return self instance for chaining. + */ + default T safariUseSimulator() { + return amend(SAFARI_USE_SIMULATOR_OPTION, true); + } + + /** + * If the value of safari:useSimulator is true, safaridriver will only use + * iOS Simulator hosts. If the value of safari:useSimulator is false, safaridriver + * will not use iOS Simulator hosts. NOTE: An Xcode installation is required + * in order to run WebDriver tests on iOS Simulator hosts. + * + * @param bool is whether to use iOS Simulator. + * @return self instance for chaining. + */ + default T setSafariUseSimulator(boolean bool) { + return amend(SAFARI_USE_SIMULATOR_OPTION, bool); + } + + /** + * Get whether to use iOS Simulator. + * + * @return true or false. + */ + default Optional doesSafariUseSimulator() { + return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_USE_SIMULATOR_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsWebkitWebrtcOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsWebkitWebrtcOption.java new file mode 100644 index 000000000..e22309f65 --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/SupportsWebkitWebrtcOption.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.safari.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Map; +import java.util.Optional; + +public interface SupportsWebkitWebrtcOption> extends + Capabilities, CanSetCapability { + String WEBKIT_WEB_RTC_OPTION = "webkit:WebRTC"; + + /** + * This capability allows a test to temporarily change Safari's policies + * for WebRTC and Media Capture. + * + * @param webrtcData WebRTC policies. + * @return self instance for chaining. + */ + default T setWebkitWebrtc(WebrtcData webrtcData) { + return amend(WEBKIT_WEB_RTC_OPTION, webrtcData.toMap()); + } + + /** + * Get WebRTC policies. + * + * @return WebRTC policies. + */ + default Optional getWebkitWebrtc() { + //noinspection unchecked + return Optional.ofNullable((Map) getCapability(WEBKIT_WEB_RTC_OPTION)) + .map(WebrtcData::new); + } +} diff --git a/src/main/java/io/appium/java_client/safari/options/WebrtcData.java b/src/main/java/io/appium/java_client/safari/options/WebrtcData.java new file mode 100644 index 000000000..b1343432e --- /dev/null +++ b/src/main/java/io/appium/java_client/safari/options/WebrtcData.java @@ -0,0 +1,77 @@ +/* + * 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.safari.options; + +import io.appium.java_client.remote.options.BaseMapOptionData; + +import java.util.Map; +import java.util.Optional; + +public class WebrtcData extends BaseMapOptionData { + public WebrtcData() { + } + + public WebrtcData(Map options) { + super(options); + } + + /** + * Normally, Safari refuses to allow media capture over insecure connections. + * This restriction is relaxed by default for WebDriver sessions for testing + * purposes (for example, a test web server not configured for HTTPS). When + * this capability is specified, Safari will revert to the normal behavior of + * preventing media capture over insecure connections. + * + * @param disabled True to disable insecure media capture. + * @return self instance for chaining. + */ + public WebrtcData withDisableInsecureMediaCapture(boolean disabled) { + return assignOptionValue("DisableInsecureMediaCapture", disabled); + } + + /** + * Get whether to disable insecure media capture. + * + * @return True or false. + */ + public Optional doesDisableInsecureMediaCapture() { + return getOptionValue("DisableInsecureMediaCapture"); + } + + /** + * To protect a user's privacy, Safari normally filters out WebRTC + * ICE candidates that correspond to internal network addresses when + * capture devices are not in use. This capability suppresses ICE candidate + * filtering so that both internal and external network addresses are + * always sent as ICE candidates. + * + * @param disabled True to disable ICE candidates filtering. + * @return self instance for chaining. + */ + public WebrtcData withDisableIceCandidateFiltering(boolean disabled) { + return assignOptionValue("DisableICECandidateFiltering", disabled); + } + + /** + * Get whether to disable ICE candidates filtering. + * + * @return True or false. + */ + public Optional doesDisableIceCandidateFiltering() { + return getOptionValue("DisableICECandidateFiltering"); + } +} diff --git a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java index 9b12ceda9..8b842ee32 100644 --- a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java +++ b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java @@ -23,12 +23,16 @@ import io.appium.java_client.android.options.localization.AppLocale; import io.appium.java_client.android.options.server.EspressoBuildConfig; import io.appium.java_client.android.options.signing.KeystoreConfig; +import io.appium.java_client.gecko.options.GeckoOptions; +import io.appium.java_client.gecko.options.Verbosity; import io.appium.java_client.ios.options.XCUITestOptions; import io.appium.java_client.ios.options.other.CommandTimeouts; import io.appium.java_client.ios.options.simulator.Permissions; import io.appium.java_client.mac.options.AppleScriptData; import io.appium.java_client.mac.options.Mac2Options; import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.safari.options.SafariOptions; +import io.appium.java_client.safari.options.WebrtcData; import io.appium.java_client.windows.options.PowerShellData; import io.appium.java_client.windows.options.WindowsOptions; import org.junit.Test; @@ -140,4 +144,40 @@ public void canBuildMac2Options() { assertTrue(options.doesSkipAppKill().orElse(false)); assertFalse(options.doesEventTimings().isPresent()); } + + @Test + public void canBuildGeckoOptions() { + GeckoOptions options = new GeckoOptions(); + options.setPlatformName(Platform.MAC.toString()); + assertEquals(Platform.MAC, options.getPlatformName()); + assertEquals(AutomationName.GECKO, options.getAutomationName().orElse(null)); + options.setNewCommandTimeout(Duration.ofSeconds(10)) + .setVerbosity(Verbosity.TRACE) + .setMozFirefoxOptions(ImmutableMap.of( + "profile", "yolo" + )); + assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null)); + assertEquals(Verbosity.TRACE, options.getVerbosity().orElse(null)); + assertEquals("yolo", options.getMozFirefoxOptions().orElse(null) + .get("profile")); + } + + @Test + public void canBuildSafariOptions() { + SafariOptions options = new SafariOptions(); + assertEquals(Platform.IOS, options.getPlatformName()); + assertEquals(AutomationName.SAFARI, options.getAutomationName().orElse(null)); + options.setNewCommandTimeout(Duration.ofSeconds(10)) + .safariUseSimulator() + .setWebkitWebrtc(new WebrtcData() + .withDisableIceCandidateFiltering(true) + .withDisableInsecureMediaCapture(true) + ); + assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null)); + assertTrue(options.doesSafariUseSimulator().orElse(false)); + assertTrue(options.getWebkitWebrtc().orElse(null) + .doesDisableIceCandidateFiltering().orElse(false)); + assertTrue(options.getWebkitWebrtc().orElse(null) + .doesDisableInsecureMediaCapture().orElse(false)); + } } From 5af35ee1bbad9329bb99e2be5672b3fd8aab4033 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 1 Nov 2021 12:53:22 +0100 Subject: [PATCH 2/2] Fix method names --- .../safari/options/SupportsSafariAutomaticInspectionOption.java | 2 +- .../safari/options/SupportsSafariAutomaticProfilingOption.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java index 04be44358..9b6e3ad29 100644 --- a/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java @@ -55,7 +55,7 @@ default T setSafariAutomaticInspection(boolean bool) { * * @return true or false. */ - default Optional doesAafariAutomaticInspection() { + default Optional doesSafariAutomaticInspection() { return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_INSPECTION_OPTION))); } } diff --git a/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java index 64a81ac29..3fcc75215 100644 --- a/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java +++ b/src/main/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java @@ -55,7 +55,7 @@ default T setSafariAutomaticProfiling(boolean bool) { * * @return true or false. */ - default Optional doesAafariAutomaticProfiling() { + default Optional doesSafariAutomaticProfiling() { return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_PROFILING_OPTION))); } }