Skip to content

Commit 6e7cf5d

Browse files
committed
[java] Creating browser name for SAFARI_TECH_PREVIEW
1 parent 268161f commit 6e7cf5d

File tree

7 files changed

+51
-34
lines changed

7 files changed

+51
-34
lines changed

‎java/CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ v4.2.0
2727
* Fix screen rotate error (#10693)
2828
* Make the action movement methods specify the button number
2929
* Convert RemoteWebElement::getLocation and ::getSize from JWP Standard to W3C Standard (#10700)
30+
* Creating browser name for SAFARI_TECH_PREVIEW
3031

3132
v4.1.4
3233
======

‎java/src/org/openqa/selenium/remote/Browser.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@
2525
*/
2626
public interface Browser {
2727

28-
String browserName();
29-
30-
default boolean is(String browserName) {
31-
return browserName().equals(browserName);
32-
}
33-
34-
default boolean is(Capabilities caps) {
35-
Require.nonNull("Capabilities", caps);
36-
return is(caps.getBrowserName());
37-
}
38-
3928
Browser CHROME = () -> "chrome";
4029
Browser EDGE = new Browser() {
4130
@Override
@@ -72,6 +61,27 @@ public boolean is(String browserName) {
7261
return browserName().equals(browserName) || "Safari".equals(browserName);
7362
}
7463
};
64+
Browser SAFARI_TECH_PREVIEW = new Browser() {
65+
@Override
66+
public String browserName() {
67+
return "Safari Technology Preview";
68+
}
69+
70+
public boolean is(String browserName) {
71+
return browserName().equals(browserName);
72+
}
73+
};
74+
75+
String browserName();
76+
77+
default boolean is(String browserName) {
78+
return browserName().equals(browserName);
79+
}
80+
81+
default boolean is(Capabilities caps) {
82+
Require.nonNull("Capabilities", caps);
83+
return is(caps.getBrowserName());
84+
}
7585

7686
default String toJson() {
7787
return browserName();

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
package org.openqa.selenium.safari;
1919

20-
import static java.util.concurrent.TimeUnit.MILLISECONDS;
21-
import static org.openqa.selenium.Platform.MAC;
22-
import static org.openqa.selenium.remote.Browser.SAFARI;
23-
2420
import com.google.auto.service.AutoService;
2521

2622
import org.openqa.selenium.Capabilities;
@@ -36,6 +32,11 @@
3632
import java.util.List;
3733
import java.util.Map;
3834

35+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
36+
import static org.openqa.selenium.Platform.MAC;
37+
import static org.openqa.selenium.remote.Browser.SAFARI;
38+
import static org.openqa.selenium.remote.Browser.SAFARI_TECH_PREVIEW;
39+
3940
public class SafariDriverService extends DriverService {
4041

4142
/**
@@ -86,7 +87,7 @@ public int score(Capabilities capabilities) {
8687

8788
if (SAFARI.is(capabilities)) {
8889
score++;
89-
} else if (SafariOptions.SAFARI_TECH_PREVIEW.equals(capabilities.getBrowserName())) {
90+
} else if (SAFARI_TECH_PREVIEW.browserName().equals(capabilities.getBrowserName())) {
9091
score++;
9192
}
9293

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
package org.openqa.selenium.safari;
1919

20-
import static org.openqa.selenium.remote.Browser.SAFARI;
21-
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
22-
2320
import org.openqa.selenium.Capabilities;
2421
import org.openqa.selenium.WebDriverException;
2522
import org.openqa.selenium.internal.Require;
@@ -28,6 +25,10 @@
2825
import java.util.Collections;
2926
import java.util.Set;
3027

28+
import static org.openqa.selenium.remote.Browser.SAFARI;
29+
import static org.openqa.selenium.remote.Browser.SAFARI_TECH_PREVIEW;
30+
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
31+
3132
/**
3233
* Class to manage options specific to {@link SafariDriver}.
3334
*
@@ -47,8 +48,6 @@
4748
*/
4849
public class SafariOptions extends AbstractDriverOptions<SafariOptions> {
4950

50-
static final String SAFARI_TECH_PREVIEW = "Safari Technology Preview";
51-
5251
public SafariOptions() {
5352
setUseTechnologyPreview(false);
5453
setCapability(BROWSER_NAME, SAFARI.browserName());
@@ -121,7 +120,7 @@ public SafariOptions setAutomaticProfiling(boolean automaticProfiling) {
121120
}
122121

123122
public boolean getUseTechnologyPreview() {
124-
return SAFARI_TECH_PREVIEW.equals(getBrowserName());
123+
return SAFARI_TECH_PREVIEW.browserName().equals(getBrowserName());
125124
}
126125

127126
/**
@@ -133,7 +132,9 @@ public boolean getUseTechnologyPreview() {
133132
*/
134133
public SafariOptions setUseTechnologyPreview(boolean useTechnologyPreview) {
135134
// Use an object here, rather than a boolean to avoid a stack overflow
136-
super.setCapability(BROWSER_NAME, useTechnologyPreview ? SAFARI_TECH_PREVIEW : "safari");
135+
super.setCapability(BROWSER_NAME,
136+
useTechnologyPreview ?
137+
SAFARI_TECH_PREVIEW.browserName() : SAFARI.browserName());
137138
return this;
138139
}
139140

‎java/src/org/openqa/selenium/safari/SafariTechPreviewDriverInfo.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.openqa.selenium.safari;
1919

20-
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
21-
2220
import com.google.auto.service.AutoService;
2321

2422
import org.openqa.selenium.Capabilities;
@@ -30,6 +28,10 @@
3028

3129
import java.util.Optional;
3230

31+
import static org.openqa.selenium.remote.Browser.SAFARI_TECH_PREVIEW;
32+
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
33+
34+
@SuppressWarnings("unused")
3335
@AutoService(WebDriverInfo.class)
3436
public class SafariTechPreviewDriverInfo implements WebDriverInfo {
3537

@@ -40,12 +42,12 @@ public String getDisplayName() {
4042

4143
@Override
4244
public Capabilities getCanonicalCapabilities() {
43-
return new ImmutableCapabilities(BROWSER_NAME, SafariOptions.SAFARI_TECH_PREVIEW);
45+
return new ImmutableCapabilities(BROWSER_NAME, SAFARI_TECH_PREVIEW.browserName());
4446
}
4547

4648
@Override
4749
public boolean isSupporting(Capabilities capabilities) {
48-
if (SafariOptions.SAFARI_TECH_PREVIEW.equalsIgnoreCase(capabilities.getBrowserName())) {
50+
if (SAFARI_TECH_PREVIEW.browserName().equalsIgnoreCase(capabilities.getBrowserName())) {
4951
return true;
5052
}
5153

@@ -77,7 +79,7 @@ public int getMaximumSimultaneousSessions() {
7779

7880
@Override
7981
public Optional<WebDriver> createDriver(Capabilities capabilities)
80-
throws SessionNotCreatedException {
82+
throws SessionNotCreatedException {
8183
if (!isAvailable()) {
8284
return Optional.empty();
8385
}

‎java/src/org/openqa/selenium/safari/SafariTechPreviewDriverService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.openqa.selenium.safari;
1919

20-
import static java.util.concurrent.TimeUnit.MILLISECONDS;
21-
2220
import com.google.auto.service.AutoService;
2321

2422
import org.openqa.selenium.Capabilities;
@@ -33,6 +31,9 @@
3331
import java.util.List;
3432
import java.util.Map;
3533

34+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
35+
import static org.openqa.selenium.remote.Browser.SAFARI_TECH_PREVIEW;
36+
3637
public class SafariTechPreviewDriverService extends DriverService {
3738

3839
/**
@@ -82,7 +83,7 @@ public static class Builder extends DriverService.Builder<
8283
public int score(Capabilities capabilities) {
8384
int score = 0;
8485

85-
if (SafariOptions.SAFARI_TECH_PREVIEW.equals(capabilities.getBrowserName())) {
86+
if (SAFARI_TECH_PREVIEW.browserName().equals(capabilities.getBrowserName())) {
8687
score++;
8788
}
8889

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import org.junit.Test;
2121
import org.junit.experimental.categories.Category;
22-
import org.openqa.selenium.ImmutableCapabilities;
2322
import org.openqa.selenium.AcceptedW3CCapabilityKeys;
23+
import org.openqa.selenium.ImmutableCapabilities;
2424
import org.openqa.selenium.remote.CapabilityType;
2525
import org.openqa.selenium.testing.UnitTests;
2626

@@ -32,6 +32,7 @@
3232
import static org.assertj.core.api.Assertions.assertThat;
3333
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3434
import static org.openqa.selenium.remote.Browser.SAFARI;
35+
import static org.openqa.selenium.remote.Browser.SAFARI_TECH_PREVIEW;
3536

3637
@Category(UnitTests.class)
3738
public class SafariOptionsTest {
@@ -53,7 +54,7 @@ public void canConstructFromCapabilities() {
5354
assertThat(options.getUseTechnologyPreview()).isFalse();
5455

5556
options = new SafariOptions(
56-
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, SafariOptions.SAFARI_TECH_PREVIEW));
57+
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, SAFARI_TECH_PREVIEW.browserName()));
5758
assertThat(options.getUseTechnologyPreview()).isTrue();
5859

5960
options = new SafariOptions(
@@ -79,7 +80,7 @@ public void settingTechnologyPreviewModeAlsoChangesBrowserName() {
7980
assertThat(options.getBrowserName()).isEqualTo(SAFARI.browserName());
8081

8182
options.setUseTechnologyPreview(true);
82-
assertThat(options.getBrowserName()).isEqualTo(SafariOptions.SAFARI_TECH_PREVIEW);
83+
assertThat(options.getBrowserName()).isEqualTo(SAFARI_TECH_PREVIEW.browserName());
8384

8485
options.setUseTechnologyPreview(false);
8586
assertThat(options.getBrowserName()).isEqualTo(SAFARI.browserName());

0 commit comments

Comments
 (0)