Skip to content

Commit f86a747

Browse files
asolntsevdiemol
andauthored
[refactor] use constant CapabilityType.ENABLE_DOWNLOADS instead of hard-coded value se:downloadsEnabled (SeleniumHQ#15867)
[refactor] use constant CapabilityType.ENABLE_DOWNLOADS instead of hard-coded value "se:downloadsEnabled" Co-authored-by: Diego Molina <[email protected]>
1 parent eff4a30 commit f86a747

File tree

10 files changed

+32
-26
lines changed

10 files changed

+32
-26
lines changed

java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java

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

1818
package org.openqa.selenium.grid.data;
1919

20+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
21+
2022
import java.io.Serializable;
2123
import java.util.Arrays;
2224
import java.util.List;
@@ -129,13 +131,13 @@ private Boolean initialMatch(Capabilities stereotype, Capabilities capabilities)
129131

130132
private Boolean managedDownloadsEnabled(Capabilities stereotype, Capabilities capabilities) {
131133
// First lets check if user wanted a Node with managed downloads enabled
132-
Object raw = capabilities.getCapability("se:downloadsEnabled");
134+
Object raw = capabilities.getCapability(ENABLE_DOWNLOADS);
133135
if (raw == null || !Boolean.parseBoolean(raw.toString())) {
134136
// User didn't ask. So lets move on to the next matching criteria
135137
return true;
136138
}
137139
// User wants managed downloads enabled to be done on this Node, let's check the stereotype
138-
raw = stereotype.getCapability("se:downloadsEnabled");
140+
raw = stereotype.getCapability(ENABLE_DOWNLOADS);
139141
// Try to match what the user requested
140142
return raw != null && Boolean.parseBoolean(raw.toString());
141143
}

java/src/org/openqa/selenium/grid/node/config/NodeOptions.java

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

1818
package org.openqa.selenium.grid.node.config;
1919

20+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
21+
2022
import com.google.common.annotations.VisibleForTesting;
2123
import com.google.common.collect.HashMultimap;
2224
import com.google.common.collect.ImmutableMap;
@@ -749,8 +751,7 @@ public Capabilities enhanceStereotype(Capabilities capabilities) {
749751
.setCapability("se:noVncPort", noVncPort());
750752
}
751753
if (isManagedDownloadsEnabled() && canConfigureDownloadsDir(capabilities)) {
752-
capabilities =
753-
new PersistentCapabilities(capabilities).setCapability("se:downloadsEnabled", true);
754+
capabilities = new PersistentCapabilities(capabilities).setCapability(ENABLE_DOWNLOADS, true);
754755
}
755756
return capabilities;
756757
}

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.openqa.selenium.grid.data.Availability.DRAINING;
2424
import static org.openqa.selenium.grid.data.Availability.UP;
2525
import static org.openqa.selenium.grid.node.CapabilityResponseEncoder.getEncoder;
26+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2627
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
2728
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
2829
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
@@ -575,7 +576,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(
575576
}
576577

577578
private boolean managedDownloadsRequested(Capabilities capabilities) {
578-
Object downloadsEnabled = capabilities.getCapability("se:downloadsEnabled");
579+
Object downloadsEnabled = capabilities.getCapability(ENABLE_DOWNLOADS);
579580
return managedDownloadsEnabled
580581
&& downloadsEnabled != null
581582
&& Boolean.parseBoolean(downloadsEnabled.toString());

java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.openqa.selenium.chromium.ChromiumDriverLogLevel.OFF;
2828
import static org.openqa.selenium.chromium.ChromiumDriverLogLevel.SEVERE;
2929
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
30+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
3031
import static org.openqa.selenium.remote.CapabilityType.TIMEOUTS;
3132

3233
import java.io.File;
@@ -98,7 +99,7 @@ void canAddW3CCompliantOptions() {
9899
assertThat(mappedOptions.get("acceptInsecureCerts")).isEqualTo(true);
99100
assertThat(mappedOptions.get("pageLoadStrategy")).hasToString("eager");
100101
assertThat(mappedOptions.get("strictFileInteractability")).isEqualTo(true);
101-
assertThat(mappedOptions.get("se:downloadsEnabled")).isEqualTo(true);
102+
assertThat(mappedOptions.get(ENABLE_DOWNLOADS)).isEqualTo(true);
102103

103104
Map<String, Long> expectedTimeouts = new HashMap<>();
104105
expectedTimeouts.put("implicit", 1000L);
@@ -239,7 +240,8 @@ void mergingOptionsWithMutableCapabilities() {
239240

240241
MutableCapabilities one = new MutableCapabilities();
241242

242-
ChromeOptions options = new ChromeOptions();
243+
org.openqa.selenium.chrome.ChromeOptions options =
244+
new org.openqa.selenium.chrome.ChromeOptions();
243245
options.addArguments("verbose");
244246
options.addArguments("silent");
245247
options.setExperimentalOption("opt1", "val1");

java/test/org/openqa/selenium/grid/data/DefaultSlotMatcherTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.grid.data;
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2122

2223
import org.junit.jupiter.api.Test;
2324
import org.openqa.selenium.Capabilities;
@@ -198,15 +199,15 @@ void fullMatchExtensionCaps() {
198199
"firefox",
199200
CapabilityType.PLATFORM_NAME,
200201
Platform.WINDOWS,
201-
"se:downloadsEnabled",
202+
ENABLE_DOWNLOADS,
202203
true);
203204
Capabilities capabilities =
204205
new ImmutableCapabilities(
205206
CapabilityType.BROWSER_NAME,
206207
"firefox",
207208
CapabilityType.PLATFORM_NAME,
208209
Platform.WINDOWS,
209-
"se:downloadsEnabled",
210+
ENABLE_DOWNLOADS,
210211
true);
211212
assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();
212213
}
@@ -307,29 +308,25 @@ void matchesBrowser() {
307308
@Test
308309
void matchDownloadsForRegularTestMatchingAgainstADownloadAwareNode() {
309310
Capabilities stereotype =
310-
new ImmutableCapabilities(
311-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
311+
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
312312
Capabilities capabilities = new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome");
313313
assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();
314314
}
315315

316316
@Test
317317
void matchDownloadsForAutoDownloadTestMatchingAgainstADownloadAwareNode() {
318318
Capabilities stereotype =
319-
new ImmutableCapabilities(
320-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
319+
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
321320
Capabilities capabilities =
322-
new ImmutableCapabilities(
323-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
321+
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
324322
assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();
325323
}
326324

327325
@Test
328326
void ensureNoMatchFOrDownloadAwareTestMatchingAgainstOrdinaryNode() {
329327
Capabilities stereotype = new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome");
330328
Capabilities capabilities =
331-
new ImmutableCapabilities(
332-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
329+
new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
333330
assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();
334331
}
335332

java/test/org/openqa/selenium/grid/node/NodeTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2525
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
2626
import static org.openqa.selenium.json.Json.MAP_TYPE;
27+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2728
import static org.openqa.selenium.remote.http.Contents.string;
2829
import static org.openqa.selenium.remote.http.HttpMethod.DELETE;
2930
import static org.openqa.selenium.remote.http.HttpMethod.GET;
@@ -124,8 +125,8 @@ public void setUp(TestInfo testInfo) throws URISyntaxException {
124125
stereotype = new ImmutableCapabilities("browserName", "cheese");
125126
caps = new ImmutableCapabilities("browserName", "cheese");
126127
if (isDownloadsTestCase) {
127-
stereotype = new ImmutableCapabilities("browserName", "chrome", "se:downloadsEnabled", true);
128-
caps = new ImmutableCapabilities("browserName", "chrome", "se:downloadsEnabled", true);
128+
stereotype = new ImmutableCapabilities("browserName", "chrome", ENABLE_DOWNLOADS, true);
129+
caps = new ImmutableCapabilities("browserName", "chrome", ENABLE_DOWNLOADS, true);
129130
}
130131

131132
uri = new URI("http://localhost:1234");

java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.junit.jupiter.api.Assertions.fail;
2727
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2828
import static org.junit.jupiter.api.Assumptions.assumeTrue;
29+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2930

3031
import com.google.common.collect.ImmutableMap;
3132
import java.io.StringReader;
@@ -156,7 +157,7 @@ boolean isDownloadEnabled(WebDriverInfo driver, String customMsg) {
156157
.filter(caps -> expected.equalsIgnoreCase(caps.getBrowserName()))
157158
.findFirst()
158159
.orElseThrow(() -> new AssertionError("Unable to find " + customMsg + " info"));
159-
return Optional.ofNullable(found.getCapability("se:downloadsEnabled"))
160+
return Optional.ofNullable(found.getCapability(ENABLE_DOWNLOADS))
160161
.map(value -> Boolean.parseBoolean(value.toString()))
161162
.orElse(Boolean.FALSE);
162163
}

java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.grid.router;
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2122
import static org.openqa.selenium.testing.drivers.Browser.IE;
2223
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
2324

@@ -75,8 +76,7 @@ public void setupServers() {
7576
options.setEnableDownloads(true);
7677

7778
capabilities =
78-
new PersistentCapabilities(browser.getCapabilities())
79-
.setCapability("se:downloadsEnabled", true);
79+
new PersistentCapabilities(browser.getCapabilities()).setCapability(ENABLE_DOWNLOADS, true);
8080

8181
Deployment deployment =
8282
DeploymentTypes.STANDALONE.start(
@@ -194,7 +194,7 @@ void errorsWhenCapabilityMissing() {
194194

195195
Capabilities caps =
196196
new PersistentCapabilities(Objects.requireNonNull(browser).getCapabilities())
197-
.setCapability("se:downloadsEnabled", false);
197+
.setCapability(ENABLE_DOWNLOADS, false);
198198

199199
WebDriver driver = new RemoteWebDriver(gridUrl, caps);
200200
Assertions.assertThrows(

java/test/org/openqa/selenium/grid/router/StressTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static java.util.concurrent.TimeUnit.MINUTES;
2222
import static org.assertj.core.api.Assertions.assertThat;
2323
import static org.junit.jupiter.api.Assertions.assertThrows;
24+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2425

2526
import java.io.StringReader;
2627
import java.util.LinkedList;
@@ -123,8 +124,7 @@ void multipleSimultaneousSessions() throws Exception {
123124
.oneOf(
124125
browser
125126
.getCapabilities()
126-
.merge(
127-
new MutableCapabilities(Map.of("se:downloadsEnabled", true))))
127+
.merge(new MutableCapabilities(Map.of(ENABLE_DOWNLOADS, true))))
128128
.address(server.getUrl())
129129
.build();
130130

java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.mockito.Mockito.mock;
2626
import static org.mockito.Mockito.verifyNoMoreInteractions;
2727
import static org.mockito.Mockito.when;
28+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2829
import static org.openqa.selenium.remote.WebDriverFixture.echoCapabilities;
2930
import static org.openqa.selenium.remote.WebDriverFixture.errorResponder;
3031
import static org.openqa.selenium.remote.WebDriverFixture.exceptionResponder;
@@ -814,7 +815,7 @@ void getDownloadableFilesReturnsType() {
814815

815816
WebDriverFixture fixture =
816817
new WebDriverFixture(
817-
new ImmutableCapabilities("se:downloadsEnabled", true),
818+
new ImmutableCapabilities(ENABLE_DOWNLOADS, true),
818819
echoCapabilities,
819820
valueResponder(ImmutableMap.of("names", expectedFiles)));
820821

0 commit comments

Comments
 (0)