Skip to content

Commit

Permalink
[java] Throwing warnings for non-W3C before creating session (Seleniu…
Browse files Browse the repository at this point in the history
…mHQ#10741)

* [java] Throwing warnings for non-W3C before creating session
  • Loading branch information
diemol authored and elgatov committed Jun 27, 2022
1 parent 2db284d commit 5611f69
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 48 deletions.
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/PersistentCapabilities.java
Expand Up @@ -53,8 +53,6 @@ public PersistentCapabilities setCapability(String name, Object value) {
Require.nonNull("Name", name);
Require.nonNull("Value", value);

W3CCapabilityKeysValidator.validateCapability(name);

return new PersistentCapabilities(this, new ImmutableCapabilities(name, value));
}

Expand Down
2 changes: 0 additions & 2 deletions java/src/org/openqa/selenium/SharedCapabilitiesMethods.java
Expand Up @@ -46,8 +46,6 @@ static boolean equals(Capabilities left, Capabilities right) {
}

static void setCapability(Map<String, Object> caps, String key, Object value) {
W3CCapabilityKeysValidator.validateCapability(key);

if ("loggingPrefs".equals(key) && value instanceof Map) {
LoggingPreferences prefs = new LoggingPreferences();
@SuppressWarnings("unchecked") Map<String, String> prefsMap = (Map<String, String>) value;
Expand Down
39 changes: 0 additions & 39 deletions java/src/org/openqa/selenium/W3CCapabilityKeysValidator.java

This file was deleted.

37 changes: 37 additions & 0 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import org.openqa.selenium.AcceptedW3CCapabilityKeys;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Beta;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -74,6 +75,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -107,6 +109,26 @@ public class RemoteWebDriver implements WebDriver,
PrintsPage,
TakesScreenshot {

private static final List<String> IE_CAPABILITY_NAMES = Arrays.asList(
"browserAttachTimeout",
"elementScrollBehavior",
"enablePersistentHover",
"ie.enableFullPageScreenshot",
"ie.forceCreateProcessApi",
"ie.forceShellWindowsApi",
"ie.ensureCleanSession",
"ie.browserCommandLineSwitches",
"ie.usePerProcessProxy",
"ignoreZoomSetting",
"initialBrowserUrl",
"ignoreProtectedModeSettings",
"requireWindowFocus",
"ie.fileUploadDialogTimeout",
"nativeEvents",
"ie.useLegacyFileUploadDialogHandling",
"ie.edgechromium",
"ie.edgepath");

// TODO: This static logger should be unified with the per-instance localLogs
private static final Logger logger = Logger.getLogger(RemoteWebDriver.class.getName());
private final ElementLocation elementLocation = new ElementLocation();
Expand Down Expand Up @@ -243,6 +265,21 @@ protected void setSessionId(String opaqueKey) {
}

protected void startSession(Capabilities capabilities) {
// Throwing warnings for non-W3C WebDriver compliant capabilities
List<String> invalid = capabilities.asMap().keySet()
.stream()
.filter(key -> !(new AcceptedW3CCapabilityKeys().test(key)))
.filter(key -> !IE_CAPABILITY_NAMES.contains(key))
.collect(Collectors.toList());

if (!invalid.isEmpty()) {
logger.log(Level.WARNING,
() -> String.format("Support for Legacy Capabilities is deprecated; " +
"You are sending the following invalid capabilities: %s; " +
"Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/",
invalid));
}

Response response = execute(DriverCommand.NEW_SESSION(singleton(capabilities)));

if (response == null) {
Expand Down
Expand Up @@ -26,7 +26,6 @@
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.UsernameAndPassword;
import org.openqa.selenium.W3CCapabilityKeysValidator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverInfo;
import org.openqa.selenium.internal.Either;
Expand Down Expand Up @@ -201,14 +200,12 @@ public RemoteWebDriverBuilder setCapability(String capabilityName, Object value)
Require.nonNull("Capability name", capabilityName);
Require.nonNull("Capability value", value);

W3CCapabilityKeysValidator.validateCapability(capabilityName);

Object previous = additionalCapabilities.put(capabilityName, value);
if (previous != null) {
LOG.log(
getDebugLogLevel(),
String.format("Overwriting capability %s. Previous value %s, new value %s", capabilityName,
previous, value));
() -> String.format("Overwriting capability %s. Previous value %s, new value %s",
capabilityName, previous, value));
}

return this;
Expand Down

0 comments on commit 5611f69

Please sign in to comment.