Skip to content

Commit

Permalink
[java] Warning when user sets w3c: true in goog:chromeOptions
Browse files Browse the repository at this point in the history
Helps with #10448
  • Loading branch information
diemol committed Jun 13, 2022
1 parent d44b82e commit 9921778
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,8 @@ 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));
}
checkNonW3CCapabilities(capabilities);
checkChromeW3CFalse(capabilities);

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

Expand Down Expand Up @@ -712,6 +700,45 @@ protected void log(SessionId sessionId, String commandName, Object toLog, When w
}
}

private void checkNonW3CCapabilities(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));
}
}

private void checkChromeW3CFalse(Capabilities capabilities) {
// Throwing warnings when the user sets `w3c: false` inside `goog:chromeOptions`
if ("chrome".equalsIgnoreCase(capabilities.getBrowserName()) &&
capabilities.asMap().containsKey("goog:chromeOptions")) {
Object capability = capabilities.getCapability("goog:chromeOptions");
boolean w3c = true;
if ((capability instanceof Map)) {
Object rawW3C = ((Map<?, ?>) capability).get("w3c");
w3c = Boolean.parseBoolean(String.valueOf(rawW3C));
}
if (!w3c) {
logger.log(
Level.WARNING,
"Setting 'w3c: true' inside 'goog:chromeOptions' will not be accepted from " +
"Selenium 4.4; " +
"Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/"
);
}
}

}

public FileDetector getFileDetector() {
return fileDetector;
}
Expand Down

0 comments on commit 9921778

Please sign in to comment.