Skip to content

Commit 9435a8a

Browse files
authored
[java] Throwing warnings for non-W3C before creating session (#10741)
* [java] Throwing warnings for non-W3C before creating session
1 parent e5a566a commit 9435a8a

File tree

5 files changed

+39
-48
lines changed

5 files changed

+39
-48
lines changed

java/src/org/openqa/selenium/PersistentCapabilities.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public PersistentCapabilities setCapability(String name, Object value) {
5353
Require.nonNull("Name", name);
5454
Require.nonNull("Value", value);
5555

56-
W3CCapabilityKeysValidator.validateCapability(name);
57-
5856
return new PersistentCapabilities(this, new ImmutableCapabilities(name, value));
5957
}
6058

java/src/org/openqa/selenium/SharedCapabilitiesMethods.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ static boolean equals(Capabilities left, Capabilities right) {
4646
}
4747

4848
static void setCapability(Map<String, Object> caps, String key, Object value) {
49-
W3CCapabilityKeysValidator.validateCapability(key);
50-
5149
if ("loggingPrefs".equals(key) && value instanceof Map) {
5250
LoggingPreferences prefs = new LoggingPreferences();
5351
@SuppressWarnings("unchecked") Map<String, String> prefsMap = (Map<String, String>) value;

java/src/org/openqa/selenium/W3CCapabilityKeysValidator.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

java/src/org/openqa/selenium/remote/RemoteWebDriver.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.collect.ImmutableMap;
2121
import com.google.common.collect.ImmutableSet;
2222

23+
import org.openqa.selenium.AcceptedW3CCapabilityKeys;
2324
import org.openqa.selenium.Alert;
2425
import org.openqa.selenium.Beta;
2526
import org.openqa.selenium.By;
@@ -74,6 +75,7 @@
7475
import java.net.MalformedURLException;
7576
import java.net.URL;
7677
import java.time.Duration;
78+
import java.util.Arrays;
7779
import java.util.Base64;
7880
import java.util.Collection;
7981
import java.util.Collections;
@@ -107,6 +109,26 @@ public class RemoteWebDriver implements WebDriver,
107109
PrintsPage,
108110
TakesScreenshot {
109111

112+
private static final List<String> IE_CAPABILITY_NAMES = Arrays.asList(
113+
"browserAttachTimeout",
114+
"elementScrollBehavior",
115+
"enablePersistentHover",
116+
"ie.enableFullPageScreenshot",
117+
"ie.forceCreateProcessApi",
118+
"ie.forceShellWindowsApi",
119+
"ie.ensureCleanSession",
120+
"ie.browserCommandLineSwitches",
121+
"ie.usePerProcessProxy",
122+
"ignoreZoomSetting",
123+
"initialBrowserUrl",
124+
"ignoreProtectedModeSettings",
125+
"requireWindowFocus",
126+
"ie.fileUploadDialogTimeout",
127+
"nativeEvents",
128+
"ie.useLegacyFileUploadDialogHandling",
129+
"ie.edgechromium",
130+
"ie.edgepath");
131+
110132
// TODO: This static logger should be unified with the per-instance localLogs
111133
private static final Logger logger = Logger.getLogger(RemoteWebDriver.class.getName());
112134
private final ElementLocation elementLocation = new ElementLocation();
@@ -243,6 +265,21 @@ protected void setSessionId(String opaqueKey) {
243265
}
244266

245267
protected void startSession(Capabilities capabilities) {
268+
// Throwing warnings for non-W3C WebDriver compliant capabilities
269+
List<String> invalid = capabilities.asMap().keySet()
270+
.stream()
271+
.filter(key -> !(new AcceptedW3CCapabilityKeys().test(key)))
272+
.filter(key -> !IE_CAPABILITY_NAMES.contains(key))
273+
.collect(Collectors.toList());
274+
275+
if (!invalid.isEmpty()) {
276+
logger.log(Level.WARNING,
277+
() -> String.format("Support for Legacy Capabilities is deprecated; " +
278+
"You are sending the following invalid capabilities: %s; " +
279+
"Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/",
280+
invalid));
281+
}
282+
246283
Response response = execute(DriverCommand.NEW_SESSION(singleton(capabilities)));
247284

248285
if (response == null) {

java/src/org/openqa/selenium/remote/RemoteWebDriverBuilder.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.openqa.selenium.ImmutableCapabilities;
2727
import org.openqa.selenium.SessionNotCreatedException;
2828
import org.openqa.selenium.UsernameAndPassword;
29-
import org.openqa.selenium.W3CCapabilityKeysValidator;
3029
import org.openqa.selenium.WebDriver;
3130
import org.openqa.selenium.WebDriverInfo;
3231
import org.openqa.selenium.internal.Either;
@@ -201,14 +200,12 @@ public RemoteWebDriverBuilder setCapability(String capabilityName, Object value)
201200
Require.nonNull("Capability name", capabilityName);
202201
Require.nonNull("Capability value", value);
203202

204-
W3CCapabilityKeysValidator.validateCapability(capabilityName);
205-
206203
Object previous = additionalCapabilities.put(capabilityName, value);
207204
if (previous != null) {
208205
LOG.log(
209206
getDebugLogLevel(),
210-
String.format("Overwriting capability %s. Previous value %s, new value %s", capabilityName,
211-
previous, value));
207+
() -> String.format("Overwriting capability %s. Previous value %s, new value %s",
208+
capabilityName, previous, value));
212209
}
213210

214211
return this;

0 commit comments

Comments
 (0)