Skip to content

Commit ba05dd9

Browse files
committed
[java] Removing deprecated safari.options
1 parent a3e4d1b commit ba05dd9

File tree

4 files changed

+53
-88
lines changed

4 files changed

+53
-88
lines changed

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public class ChromeDriverService extends DriverService {
8181
* System property that defines whether the chromedriver executable should check for build
8282
* version compatibility between chromedriver and the browser.
8383
*/
84-
public static final String
85-
CHROME_DRIVER_DISABLE_BUILD_CHECK =
84+
public static final String CHROME_DRIVER_DISABLE_BUILD_CHECK =
8685
"webdriver.chrome.disableBuildCheck";
8786

8887
/**

java/src/org/openqa/selenium/safari/SafariDriverService.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ public int score(Capabilities capabilities) {
102102
score++;
103103
}
104104

105-
if (capabilities.getCapability(SafariOptions.CAPABILITY) != null) {
106-
score++;
107-
}
108-
109-
if (capabilities.getCapability("se:safari:techPreview") != null) {
110-
score++;
111-
}
112-
113105
return score;
114106
}
115107

java/src/org/openqa/selenium/safari/SafariOptions.java

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717

1818
package org.openqa.selenium.safari;
1919

20+
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
21+
2022
import org.openqa.selenium.Capabilities;
21-
import org.openqa.selenium.MutableCapabilities;
2223
import org.openqa.selenium.WebDriverException;
2324
import org.openqa.selenium.internal.Require;
2425
import org.openqa.selenium.remote.AbstractDriverOptions;
26+
import org.openqa.selenium.remote.BrowserType;
2527

2628
import java.util.Collections;
27-
import java.util.Map;
2829
import java.util.Set;
2930

30-
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
31-
3231
/**
3332
* Class to manage options specific to {@link SafariDriver}.
3433
*
@@ -50,22 +49,9 @@ public class SafariOptions extends AbstractDriverOptions<SafariOptions> {
5049

5150
static final String SAFARI_TECH_PREVIEW = "Safari Technology Preview";
5251

53-
/**
54-
* Key used to store SafariOptions in a {@link Capabilities} object.
55-
* @deprecated No replacement. Use the methods on this class
56-
*/
57-
@Deprecated
58-
public static final String CAPABILITY = "safari.options";
59-
60-
private interface Option {
61-
// Defined by Apple
62-
String AUTOMATIC_INSPECTION = "safari:automaticInspection";
63-
String AUTOMATIC_PROFILING = "safari:automaticProfiling";
64-
}
65-
6652
public SafariOptions() {
6753
setUseTechnologyPreview(false);
68-
setCapability(BROWSER_NAME, "safari");
54+
setCapability(BROWSER_NAME, BrowserType.SAFARI);
6955
}
7056

7157
public SafariOptions(Capabilities source) {
@@ -74,6 +60,21 @@ public SafariOptions(Capabilities source) {
7460
source.getCapabilityNames().forEach(name -> setCapability(name, source.getCapability(name)));
7561
}
7662

63+
/**
64+
* Construct a {@link SafariOptions} instance from given capabilities.
65+
*
66+
* @param capabilities Desired capabilities from which the options are derived.
67+
* @return SafariOptions
68+
* @throws WebDriverException If an error occurred during the reconstruction of the options
69+
*/
70+
public static SafariOptions fromCapabilities(Capabilities capabilities)
71+
throws WebDriverException {
72+
if (capabilities instanceof SafariOptions) {
73+
return (SafariOptions) capabilities;
74+
}
75+
return new SafariOptions(capabilities);
76+
}
77+
7778
@Override
7879
public SafariOptions merge(Capabilities extraCapabilities) {
7980
Require.nonNull("Capabilities to merge", extraCapabilities);
@@ -87,27 +88,8 @@ public SafariOptions merge(Capabilities extraCapabilities) {
8788
return newInstance;
8889
}
8990

90-
/**
91-
* Construct a {@link SafariOptions} instance from given capabilities.
92-
* When the {@link #CAPABILITY} capability is set, all other capabilities will be ignored!
93-
*
94-
* @param capabilities Desired capabilities from which the options are derived.
95-
* @return SafariOptions
96-
* @throws WebDriverException If an error occurred during the reconstruction of the options
97-
*/
98-
public static SafariOptions fromCapabilities(Capabilities capabilities)
99-
throws WebDriverException {
100-
if (capabilities instanceof SafariOptions) {
101-
return (SafariOptions) capabilities;
102-
}
103-
Object cap = capabilities.getCapability(SafariOptions.CAPABILITY);
104-
if (cap instanceof SafariOptions) {
105-
return (SafariOptions) cap;
106-
} else if (cap instanceof Map) {
107-
return new SafariOptions(new MutableCapabilities(((Map<String, ?>) cap)));
108-
} else {
109-
return new SafariOptions(capabilities);
110-
}
91+
public boolean getAutomaticInspection() {
92+
return Boolean.TRUE.equals(getCapability(Option.AUTOMATIC_INSPECTION));
11193
}
11294

11395
// Setters
@@ -124,45 +106,41 @@ public SafariOptions setAutomaticInspection(boolean automaticInspection) {
124106
return this;
125107
}
126108

109+
public boolean getAutomaticProfiling() {
110+
return Boolean.TRUE.equals(is(Option.AUTOMATIC_PROFILING));
111+
}
112+
127113
/**
128114
* Instruct the SafariDriver to enable the Automatic profiling if true, otherwise disable
129115
* the automatic profiling. Defaults to disabling the automatic profiling.
130116
*
131117
* @param automaticProfiling If true, the SafariDriver will enable the Automation Profiling,
132-
* otherwise will disable.
118+
* otherwise will disable.
133119
*/
134120
public SafariOptions setAutomaticProfiling(boolean automaticProfiling) {
135121
setCapability(Option.AUTOMATIC_PROFILING, automaticProfiling);
136122
return this;
137123
}
138124

125+
// Getters
126+
127+
public boolean getUseTechnologyPreview() {
128+
return SAFARI_TECH_PREVIEW.equals(getBrowserName());
129+
}
130+
139131
/**
140132
* Instruct the SafariDriver to use the Safari Technology Preview if true, otherwise use the
141133
* release version of Safari. Defaults to using the release version of Safari.
142134
*
143135
* @param useTechnologyPreview If true, the SafariDriver will use the Safari Technology Preview,
144-
* otherwise will use the release version of Safari.
136+
* otherwise will use the release version of Safari.
145137
*/
146138
public SafariOptions setUseTechnologyPreview(boolean useTechnologyPreview) {
147139
// Use an object here, rather than a boolean to avoid a stack overflow
148140
super.setCapability(BROWSER_NAME, useTechnologyPreview ? SAFARI_TECH_PREVIEW : "safari");
149141
return this;
150142
}
151143

152-
// Getters
153-
154-
public boolean getAutomaticInspection() {
155-
return Boolean.TRUE.equals(getCapability(Option.AUTOMATIC_INSPECTION));
156-
}
157-
158-
public boolean getAutomaticProfiling() {
159-
return Boolean.TRUE.equals(is(Option.AUTOMATIC_PROFILING));
160-
}
161-
162-
public boolean getUseTechnologyPreview() {
163-
return SAFARI_TECH_PREVIEW.equals(getBrowserName());
164-
}
165-
166144
@Override
167145
protected Set<String> getExtraCapabilityNames() {
168146
return Collections.emptySet();
@@ -172,4 +150,11 @@ protected Set<String> getExtraCapabilityNames() {
172150
protected Object getExtraCapability(String capabilityName) {
173151
return null;
174152
}
153+
154+
private interface Option {
155+
156+
// Defined by Apple
157+
String AUTOMATIC_INSPECTION = "safari:automaticInspection";
158+
String AUTOMATIC_PROFILING = "safari:automaticProfiling";
159+
}
175160
}

java/test/org/openqa/selenium/safari/SafariOptionsTest.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@
1717

1818
package org.openqa.selenium.safari;
1919

20+
import static java.util.stream.Collectors.toSet;
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
23+
2024
import org.junit.Test;
2125
import org.junit.experimental.categories.Category;
2226
import org.openqa.selenium.ImmutableCapabilities;
2327
import org.openqa.selenium.remote.AcceptedW3CCapabilityKeys;
28+
import org.openqa.selenium.remote.BrowserType;
2429
import org.openqa.selenium.remote.CapabilityType;
2530
import org.openqa.selenium.testing.UnitTests;
2631

27-
import java.util.HashMap;
2832
import java.util.Map;
2933
import java.util.Set;
3034
import java.util.function.Predicate;
3135

32-
import static java.util.Collections.singletonMap;
33-
import static java.util.stream.Collectors.toSet;
34-
import static org.assertj.core.api.Assertions.assertThat;
35-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
36-
3736
@Category(UnitTests.class)
3837
public class SafariOptionsTest {
3938

@@ -50,28 +49,18 @@ public void roundTrippingToCapabilitiesAndBackWorks() {
5049

5150
@Test
5251
public void canConstructFromCapabilities() {
53-
Map<String, Object> embeddedOptions = new HashMap<>();
54-
embeddedOptions.put("technologyPreview", true);
55-
5652
SafariOptions options = new SafariOptions();
5753
assertThat(options.getUseTechnologyPreview()).isFalse();
5854

59-
options = new SafariOptions(new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "Safari Technology Preview"));
55+
options = new SafariOptions(
56+
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, SafariOptions.SAFARI_TECH_PREVIEW));
6057
assertThat(options.getUseTechnologyPreview()).isTrue();
6158

62-
options = new SafariOptions(new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "safari"));
59+
options = new SafariOptions(
60+
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, BrowserType.SAFARI));
6361
assertThat(options.getUseTechnologyPreview()).isFalse();
6462
}
6563

66-
@Test
67-
public void newerStyleCapabilityWinsOverOlderStyle() {
68-
SafariOptions options = new SafariOptions(new ImmutableCapabilities(
69-
CapabilityType.BROWSER_NAME, "Safari Technology Preview",
70-
SafariOptions.CAPABILITY, singletonMap("technologyPreview", false)));
71-
72-
assertThat(options.getUseTechnologyPreview()).isTrue();
73-
}
74-
7564
@Test
7665
public void canSetAutomaticInspection() {
7766
SafariOptions options = new SafariOptions().setAutomaticInspection(true);
@@ -87,13 +76,13 @@ public void canSetAutomaticProfiling() {
8776
@Test
8877
public void settingTechnologyPreviewModeAlsoChangesBrowserName() {
8978
SafariOptions options = new SafariOptions();
90-
assertThat(options.getBrowserName()).isEqualTo("safari");
79+
assertThat(options.getBrowserName()).isEqualTo(BrowserType.SAFARI);
9180

9281
options.setUseTechnologyPreview(true);
93-
assertThat(options.getBrowserName()).isEqualTo("Safari Technology Preview");
82+
assertThat(options.getBrowserName()).isEqualTo(SafariOptions.SAFARI_TECH_PREVIEW);
9483

9584
options.setUseTechnologyPreview(false);
96-
assertThat(options.getBrowserName()).isEqualTo("safari");
85+
assertThat(options.getBrowserName()).isEqualTo(BrowserType.SAFARI);
9786
}
9887

9988
@Test

0 commit comments

Comments
 (0)