Skip to content

Commit 6e09f51

Browse files
committed
Use browser name to determine if using Safari Tech Preview
The browser names are different when using the Tech Preview. Might as well take advantage of that.
1 parent 6d56181 commit 6e09f51

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
*/
5050
public class SafariOptions extends MutableCapabilities {
5151

52+
private static final String SAFARI_TECH_PREVIEW = "Safari Technology Preview";
53+
5254
/**
5355
* Key used to store SafariOptions in a {@link Capabilities} object.
5456
* @deprecated No replacement. Use the methods on this class
@@ -63,9 +65,6 @@ private interface Option {
6365
// Defined by Apple
6466
String AUTOMATIC_INSPECTION = "safari:automaticInspection";
6567
String AUTOMATIC_PROFILING = "safari:automaticProfiling";
66-
67-
// Defined by us
68-
String TECH_PREVIEW = "se:safari:techPreview";
6968
}
7069

7170
private Map<String, Object> options = new TreeMap<>();
@@ -155,14 +154,13 @@ public SafariOptions setAutomaticProfiling(boolean automaticProfiling) {
155154
public SafariOptions setUseTechnologyPreview(boolean useTechnologyPreview) {
156155
options.put(Option.TECHNOLOGY_PREVIEW, useTechnologyPreview);
157156
// Use an object here, rather than a boolean to avoid a stack overflow
158-
super.setCapability(Option.TECH_PREVIEW, Boolean.valueOf(useTechnologyPreview));
159-
super.setCapability(BROWSER_NAME, useTechnologyPreview ? "Safari Technology Preview" : "safari");
157+
super.setCapability(BROWSER_NAME, useTechnologyPreview ? SAFARI_TECH_PREVIEW : "safari");
160158
return this;
161159
}
162160

163161
@Override
164162
public void setCapability(String key, Object value) {
165-
if (Option.TECHNOLOGY_PREVIEW.equals(key) || Option.TECH_PREVIEW.equals(key)) {
163+
if (Option.TECHNOLOGY_PREVIEW.equals(key)) {
166164
setUseTechnologyPreview(Boolean.valueOf(value.toString()));
167165
} else {
168166
super.setCapability(key, value);
@@ -171,7 +169,7 @@ public void setCapability(String key, Object value) {
171169

172170
@Override
173171
public void setCapability(String key, boolean value) {
174-
if (Option.TECHNOLOGY_PREVIEW.equals(key) || Option.TECH_PREVIEW.equals(key)) {
172+
if (Option.TECHNOLOGY_PREVIEW.equals(key)) {
175173
setUseTechnologyPreview(value);
176174
} else {
177175
super.setCapability(key, value);
@@ -194,7 +192,8 @@ public boolean getAutomaticProfiling() {
194192
}
195193

196194
public boolean getUseTechnologyPreview() {
197-
return is(Option.TECH_PREVIEW)|| options.get(Option.TECHNOLOGY_PREVIEW) == Boolean.TRUE;
195+
return SAFARI_TECH_PREVIEW.equals(getBrowserName()) ||
196+
options.get(Option.TECHNOLOGY_PREVIEW) == Boolean.TRUE;
198197
}
199198

200199
// (De)serialization of the options

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.junit.Test;
2727
import org.openqa.selenium.ImmutableCapabilities;
28+
import org.openqa.selenium.remote.CapabilityType;
2829

2930
import java.util.HashMap;
3031
import java.util.Map;
@@ -57,18 +58,18 @@ public void canConstructFromCapabilities() {
5758
options = new SafariOptions(new ImmutableCapabilities(SafariOptions.CAPABILITY, embeddedOptions));
5859
assertFalse(options.getUseTechnologyPreview());
5960

60-
options = new SafariOptions(new ImmutableCapabilities("se:safari:techPreview", true));
61+
options = new SafariOptions(new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "Safari Technology Preview"));
6162
assertTrue(options.getUseTechnologyPreview());
6263

63-
options = new SafariOptions(new ImmutableCapabilities("se:safari:techPreview", false));
64+
options = new SafariOptions(new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "safari"));
6465
assertFalse(options.getUseTechnologyPreview());
6566
}
6667

6768
@Test
6869
public void newerStyleCapabilityWinsOverOlderStyle() {
6970
SafariOptions options = new SafariOptions(new ImmutableCapabilities(
70-
SafariOptions.CAPABILITY, ImmutableMap.of("technologyPreview", false),
71-
"se:safari:techPreview", true));
71+
CapabilityType.BROWSER_NAME, "Safari Technology Preview",
72+
SafariOptions.CAPABILITY, ImmutableMap.of("technologyPreview", false)));
7273

7374
assertTrue(options.getUseTechnologyPreview());
7475
}

0 commit comments

Comments
 (0)