Skip to content

Commit 5bc1227

Browse files
feat: Add Safari driver options (#1576)
1 parent c2981de commit 5bc1227

13 files changed

+763
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.safari;
18+
19+
import io.appium.java_client.AppiumDriver;
20+
import io.appium.java_client.remote.AutomationName;
21+
import io.appium.java_client.service.local.AppiumDriverLocalService;
22+
import io.appium.java_client.service.local.AppiumServiceBuilder;
23+
import org.openqa.selenium.Capabilities;
24+
import org.openqa.selenium.Platform;
25+
import org.openqa.selenium.remote.HttpCommandExecutor;
26+
import org.openqa.selenium.remote.http.HttpClient;
27+
28+
import java.net.URL;
29+
30+
/**
31+
* GeckoDriver is an officially supported Appium driver
32+
* created to automate mobile Safari browser. The driver uses W3C
33+
* WebDriver protocol and is built on top of Apple's safaridriver
34+
* server. Read https://github.com/appium/appium-safari-driver
35+
* for more details on how to configure and use it.
36+
*
37+
* @since Appium 1.20.0
38+
*/
39+
public class SafariDriver extends AppiumDriver {
40+
private static final String PLATFORM_NAME = Platform.IOS.toString();
41+
private static final String AUTOMATION_NAME = AutomationName.SAFARI;
42+
43+
public SafariDriver(HttpCommandExecutor executor, Capabilities capabilities) {
44+
super(executor, ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME));
45+
}
46+
47+
public SafariDriver(URL remoteAddress, Capabilities capabilities) {
48+
super(remoteAddress, ensurePlatformAndAutomationNames(
49+
capabilities, PLATFORM_NAME, AUTOMATION_NAME));
50+
}
51+
52+
public SafariDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) {
53+
super(remoteAddress, httpClientFactory, ensurePlatformAndAutomationNames(
54+
capabilities, PLATFORM_NAME, AUTOMATION_NAME));
55+
}
56+
57+
public SafariDriver(AppiumDriverLocalService service, Capabilities capabilities) {
58+
super(service, ensurePlatformAndAutomationNames(
59+
capabilities, PLATFORM_NAME, AUTOMATION_NAME));
60+
}
61+
62+
public SafariDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,
63+
Capabilities capabilities) {
64+
super(service, httpClientFactory, ensurePlatformAndAutomationNames(
65+
capabilities, PLATFORM_NAME, AUTOMATION_NAME));
66+
}
67+
68+
public SafariDriver(AppiumServiceBuilder builder, Capabilities capabilities) {
69+
super(builder, ensurePlatformAndAutomationNames(
70+
capabilities, PLATFORM_NAME, AUTOMATION_NAME));
71+
}
72+
73+
public SafariDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,
74+
Capabilities capabilities) {
75+
super(builder, httpClientFactory, ensurePlatformAndAutomationNames(
76+
capabilities, PLATFORM_NAME, AUTOMATION_NAME));
77+
}
78+
79+
public SafariDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) {
80+
super(httpClientFactory, ensurePlatformAndAutomationNames(
81+
capabilities, PLATFORM_NAME, AUTOMATION_NAME));
82+
}
83+
84+
public SafariDriver(Capabilities capabilities) {
85+
super(ensurePlatformAndAutomationNames(capabilities, PLATFORM_NAME, AUTOMATION_NAME));
86+
}
87+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.safari.options;
18+
19+
import io.appium.java_client.remote.AutomationName;
20+
import io.appium.java_client.remote.options.BaseOptions;
21+
import io.appium.java_client.remote.options.SupportsAcceptInsecureCertsOption;
22+
import io.appium.java_client.remote.options.SupportsBrowserNameOption;
23+
import io.appium.java_client.remote.options.SupportsBrowserVersionOption;
24+
import io.appium.java_client.remote.options.SupportsPageLoadStrategyOption;
25+
import io.appium.java_client.remote.options.SupportsProxyOption;
26+
import io.appium.java_client.remote.options.SupportsSetWindowRectOption;
27+
import io.appium.java_client.remote.options.SupportsUnhandledPromptBehaviorOption;
28+
import org.openqa.selenium.Capabilities;
29+
import org.openqa.selenium.Platform;
30+
31+
import java.util.Map;
32+
33+
/**
34+
* https://github.com/appium/appium-safari-driver#usage
35+
*/
36+
public class SafariOptions extends BaseOptions<SafariOptions> implements
37+
SupportsBrowserNameOption<SafariOptions>,
38+
SupportsBrowserVersionOption<SafariOptions>,
39+
SupportsSafariPlatformVersionOption<SafariOptions>,
40+
SupportsSafariPlatformBuildVersionOption<SafariOptions>,
41+
SupportsSafariUseSimulatorOption<SafariOptions>,
42+
SupportsSafariDeviceTypeOption<SafariOptions>,
43+
SupportsSafariDeviceNameOption<SafariOptions>,
44+
SupportsSafariDeviceUdidOption<SafariOptions>,
45+
SupportsSafariAutomaticInspectionOption<SafariOptions>,
46+
SupportsSafariAutomaticProfilingOption<SafariOptions>,
47+
SupportsWebkitWebrtcOption<SafariOptions>,
48+
SupportsAcceptInsecureCertsOption<SafariOptions>,
49+
SupportsPageLoadStrategyOption<SafariOptions>,
50+
SupportsSetWindowRectOption<SafariOptions>,
51+
SupportsProxyOption<SafariOptions>,
52+
SupportsUnhandledPromptBehaviorOption<SafariOptions> {
53+
public SafariOptions() {
54+
setCommonOptions();
55+
}
56+
57+
public SafariOptions(Capabilities source) {
58+
super(source);
59+
setCommonOptions();
60+
}
61+
62+
public SafariOptions(Map<String, ?> source) {
63+
super(source);
64+
setCommonOptions();
65+
}
66+
67+
private void setCommonOptions() {
68+
setPlatformName(Platform.IOS.toString());
69+
setAutomationName(AutomationName.SAFARI);
70+
}
71+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.safari.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean;
26+
27+
public interface SupportsSafariAutomaticInspectionOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String SAFARI_AUTOMATIC_INSPECTION_OPTION = "safari:automaticInspection";
30+
31+
/**
32+
* Enforces safaridriver to use Automatic Inspection.
33+
*
34+
* @return self instance for chaining.
35+
*/
36+
default T safariAutomaticInspection() {
37+
return amend(SAFARI_AUTOMATIC_INSPECTION_OPTION, true);
38+
}
39+
40+
/**
41+
* This capability instructs Safari to preload the Web Inspector and JavaScript
42+
* debugger in the background prior to returning a newly-created window.
43+
* To pause the test's execution in JavaScript and bring up Web Inspector's
44+
* Debugger tab, you can simply evaluate a debugger; statement in the test page.
45+
*
46+
* @param bool Whether to use automatic inspection.
47+
* @return self instance for chaining.
48+
*/
49+
default T setSafariAutomaticInspection(boolean bool) {
50+
return amend(SAFARI_AUTOMATIC_INSPECTION_OPTION, bool);
51+
}
52+
53+
/**
54+
* Get whether to use automatic inspection.
55+
*
56+
* @return true or false.
57+
*/
58+
default Optional<Boolean> doesSafariAutomaticInspection() {
59+
return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_INSPECTION_OPTION)));
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.safari.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean;
26+
27+
public interface SupportsSafariAutomaticProfilingOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String SAFARI_AUTOMATIC_PROFILING_OPTION = "safari:automaticProfiling";
30+
31+
/**
32+
* Enforces safaridriver to use Automatic Inspection.
33+
*
34+
* @return self instance for chaining.
35+
*/
36+
default T safariAutomaticProfiling() {
37+
return amend(SAFARI_AUTOMATIC_PROFILING_OPTION, true);
38+
}
39+
40+
/**
41+
* This capability instructs Safari to preload the Web Inspector and start
42+
* a Timeline recording in the background prior to returning a newly-created
43+
* window. To view the recording, open the Web Inspector through Safari's
44+
* Develop menu.
45+
*
46+
* @param bool Whether to use automatic profiling.
47+
* @return self instance for chaining.
48+
*/
49+
default T setSafariAutomaticProfiling(boolean bool) {
50+
return amend(SAFARI_AUTOMATIC_PROFILING_OPTION, bool);
51+
}
52+
53+
/**
54+
* Get whether to use automatic profiling.
55+
*
56+
* @return true or false.
57+
*/
58+
default Optional<Boolean> doesSafariAutomaticProfiling() {
59+
return Optional.ofNullable(toSafeBoolean(getCapability(SAFARI_AUTOMATIC_PROFILING_OPTION)));
60+
}
61+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.safari.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
public interface SupportsSafariDeviceNameOption<T extends BaseOptions<T>> extends
26+
Capabilities, CanSetCapability<T> {
27+
String SAFARI_DEVICE_NAME_OPTION = "safari:deviceName";
28+
29+
/**
30+
* safaridriver will only create a session using hosts whose device name
31+
* matches the value of safari:deviceName. Device names are compared
32+
* case-insensitively. NOTE: Device names for connected devices are shown in
33+
* iTunes. If Xcode is installed, device names for connected devices are available
34+
* via the output of instruments(1) and in the Devices and Simulators window
35+
* (accessed in Xcode via "Window -&gt; Devices and Simulators").
36+
*
37+
* @param deviceName Device name.
38+
* @return self instance for chaining.
39+
*/
40+
default T setSafariDeviceName(String deviceName) {
41+
return amend(SAFARI_DEVICE_NAME_OPTION, deviceName);
42+
}
43+
44+
/**
45+
* Get the name of the device.
46+
*
47+
* @return String representing the name of the device.
48+
*/
49+
default Optional<String> getSafariDeviceName() {
50+
return Optional.ofNullable((String) getCapability(SAFARI_DEVICE_NAME_OPTION));
51+
}
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.safari.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
public interface SupportsSafariDeviceTypeOption<T extends BaseOptions<T>> extends
26+
Capabilities, CanSetCapability<T> {
27+
String SAFARI_DEVICE_TYPE_OPTION = "safari:deviceType";
28+
29+
/**
30+
* If the value of safari:deviceType is 'iPhone', safaridriver will only create a session
31+
* using an iPhone device or iPhone simulator. If the value of safari:deviceType is 'iPad',
32+
* safaridriver will only create a session using an iPad device or iPad simulator.
33+
* Values of safari:deviceType are compared case-insensitively.
34+
*
35+
* @param deviceType Device type name.
36+
* @return self instance for chaining.
37+
*/
38+
default T setSafariDeviceType(String deviceType) {
39+
return amend(SAFARI_DEVICE_TYPE_OPTION, deviceType);
40+
}
41+
42+
/**
43+
* Get the type of the device.
44+
*
45+
* @return String representing the type of the device.
46+
*/
47+
default Optional<String> getSafariDeviceType() {
48+
return Optional.ofNullable((String) getCapability(SAFARI_DEVICE_TYPE_OPTION));
49+
}
50+
}

0 commit comments

Comments
 (0)