Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Throwing warnings for non-W3C before creating session #10741

Merged
merged 3 commits into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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