-
-
Notifications
You must be signed in to change notification settings - Fork 765
feat: Add Safari driver options #1576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/main/java/io/appium/java_client/safari/SafariDriver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
src/main/java/io/appium/java_client/safari/options/SafariOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<SafariOptions> implements | ||
| SupportsBrowserNameOption<SafariOptions>, | ||
| SupportsBrowserVersionOption<SafariOptions>, | ||
| SupportsSafariPlatformVersionOption<SafariOptions>, | ||
| SupportsSafariPlatformBuildVersionOption<SafariOptions>, | ||
| SupportsSafariUseSimulatorOption<SafariOptions>, | ||
| SupportsSafariDeviceTypeOption<SafariOptions>, | ||
| SupportsSafariDeviceNameOption<SafariOptions>, | ||
| SupportsSafariDeviceUdidOption<SafariOptions>, | ||
| SupportsSafariAutomaticInspectionOption<SafariOptions>, | ||
| SupportsSafariAutomaticProfilingOption<SafariOptions>, | ||
| SupportsWebkitWebrtcOption<SafariOptions>, | ||
| SupportsAcceptInsecureCertsOption<SafariOptions>, | ||
| SupportsPageLoadStrategyOption<SafariOptions>, | ||
| SupportsSetWindowRectOption<SafariOptions>, | ||
| SupportsProxyOption<SafariOptions>, | ||
| SupportsUnhandledPromptBehaviorOption<SafariOptions> { | ||
| public SafariOptions() { | ||
| setCommonOptions(); | ||
| } | ||
|
|
||
| public SafariOptions(Capabilities source) { | ||
| super(source); | ||
| setCommonOptions(); | ||
| } | ||
|
|
||
| public SafariOptions(Map<String, ?> source) { | ||
| super(source); | ||
| setCommonOptions(); | ||
| } | ||
|
|
||
| private void setCommonOptions() { | ||
| setPlatformName(Platform.IOS.toString()); | ||
| setAutomationName(AutomationName.SAFARI); | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
...in/java/io/appium/java_client/safari/options/SupportsSafariAutomaticInspectionOption.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<T extends BaseOptions<T>> extends | ||
| Capabilities, CanSetCapability<T> { | ||
| 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<Boolean> doesAafariAutomaticInspection() { | ||
| return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_INSPECTION_OPTION))); | ||
| } | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
...ain/java/io/appium/java_client/safari/options/SupportsSafariAutomaticProfilingOption.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<T extends BaseOptions<T>> extends | ||
| Capabilities, CanSetCapability<T> { | ||
| 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<Boolean> doesAafariAutomaticProfiling() { | ||
SrinivasanTarget marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_PROFILING_OPTION))); | ||
| } | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceNameOption.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<T extends BaseOptions<T>> extends | ||
| Capabilities, CanSetCapability<T> { | ||
| 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<String> getSafariDeviceName() { | ||
| return Optional.ofNullable((String) getCapability(SAFARI_DEVICE_NAME_OPTION)); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/main/java/io/appium/java_client/safari/options/SupportsSafariDeviceTypeOption.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<T extends BaseOptions<T>> extends | ||
| Capabilities, CanSetCapability<T> { | ||
| 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<String> getSafariDeviceType() { | ||
| return Optional.ofNullable((String) getCapability(SAFARI_DEVICE_TYPE_OPTION)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.