Skip to content

Commit 57e97fc

Browse files
committed
[refactor] use constant CapabilityType.ENABLE_DOWNLOADS instead of hard-coded value "se:downloadsEnabled"
1 parent a2dc04a commit 57e97fc

10 files changed

Lines changed: 31 additions & 19 deletions

File tree

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 & 1 deletion
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;
@@ -750,7 +752,7 @@ public Capabilities enhanceStereotype(Capabilities capabilities) {
750752
}
751753
if (isManagedDownloadsEnabled() && canConfigureDownloadsDir(capabilities)) {
752754
capabilities =
753-
new PersistentCapabilities(capabilities).setCapability("se:downloadsEnabled", true);
755+
new PersistentCapabilities(capabilities).setCapability(ENABLE_DOWNLOADS, true);
754756
}
755757
return capabilities;
756758
}

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: 3 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,7 @@ void mergingOptionsWithMutableCapabilities() {
239240

240241
MutableCapabilities one = new MutableCapabilities();
241242

242-
ChromeOptions options = new ChromeOptions();
243+
org.openqa.selenium.chrome.ChromeOptions options = new org.openqa.selenium.chrome.ChromeOptions();
243244
options.addArguments("verbose");
244245
options.addArguments("silent");
245246
options.setExperimentalOption("opt1", "val1");

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

Lines changed: 7 additions & 6 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
}
@@ -308,7 +309,7 @@ void matchesBrowser() {
308309
void matchDownloadsForRegularTestMatchingAgainstADownloadAwareNode() {
309310
Capabilities stereotype =
310311
new ImmutableCapabilities(
311-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
312+
CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
312313
Capabilities capabilities = new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome");
313314
assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();
314315
}
@@ -317,10 +318,10 @@ void matchDownloadsForRegularTestMatchingAgainstADownloadAwareNode() {
317318
void matchDownloadsForAutoDownloadTestMatchingAgainstADownloadAwareNode() {
318319
Capabilities stereotype =
319320
new ImmutableCapabilities(
320-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
321+
CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
321322
Capabilities capabilities =
322323
new ImmutableCapabilities(
323-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
324+
CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
324325
assertThat(slotMatcher.matches(stereotype, capabilities)).isTrue();
325326
}
326327

@@ -329,7 +330,7 @@ void ensureNoMatchFOrDownloadAwareTestMatchingAgainstOrdinaryNode() {
329330
Capabilities stereotype = new ImmutableCapabilities(CapabilityType.BROWSER_NAME, "chrome");
330331
Capabilities capabilities =
331332
new ImmutableCapabilities(
332-
CapabilityType.BROWSER_NAME, "chrome", "se:downloadsEnabled", true);
333+
CapabilityType.BROWSER_NAME, "chrome", ENABLE_DOWNLOADS, true);
333334
assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();
334335
}
335336

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 & 2 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

@@ -76,7 +77,7 @@ public void setupServers() {
7677

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

8182
Deployment deployment =
8283
DeploymentTypes.STANDALONE.start(
@@ -194,7 +195,7 @@ void errorsWhenCapabilityMissing() {
194195

195196
Capabilities caps =
196197
new PersistentCapabilities(Objects.requireNonNull(browser).getCapabilities())
197-
.setCapability("se:downloadsEnabled", false);
198+
.setCapability(ENABLE_DOWNLOADS, false);
198199

199200
WebDriver driver = new RemoteWebDriver(gridUrl, caps);
200201
Assertions.assertThrows(

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

Lines changed: 2 additions & 1 deletion
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;
@@ -124,7 +125,7 @@ void multipleSimultaneousSessions() throws Exception {
124125
browser
125126
.getCapabilities()
126127
.merge(
127-
new MutableCapabilities(Map.of("se:downloadsEnabled", true))))
128+
new MutableCapabilities(Map.of(ENABLE_DOWNLOADS, true))))
128129
.address(server.getUrl())
129130
.build();
130131

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)