[java] Making sure "loggingPrefs" only affects Chrome
Fixes
package org.openqa.selenium.remote.session;
-import org.openqa.selenium.remote.CapabilityType;
-
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.stream.Collectors;
import static org.openqa.selenium.remote.Browser.CHROME;
+import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
public class ChromeFilter implements CapabilitiesFilter {
@Override
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
+ String browserName = (String) unmodifiedCaps.getOrDefault(BROWSER_NAME, "");
Map<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
.filter(
entry ->
- (CapabilityType.BROWSER_NAME.equals(entry.getKey()) && CHROME.is(String.valueOf(entry.getValue()))) ||
+ (BROWSER_NAME.equals(entry.getKey()) && CHROME.is(String.valueOf(entry.getValue()))) ||
entry.getKey().startsWith("goog:") ||
"chromeOptions".equals(entry.getKey()) ||
- "loggingPrefs".equals(entry.getKey()))
+ ("loggingPrefs".equals(entry.getKey()) && CHROME.is(browserName)))
.filter(entry -> Objects.nonNull(entry.getValue()))
.distinct()
.collect(Collectors.toMap(
TreeMap::new));
// We may need to map the chromeoptions to the new form
- if (caps.containsKey("chromeOptions") && !caps.containsKey("goog:chromeOptions")) {
+ if (caps.containsKey("chromeOptions") && !caps.containsKey("goog:chromeOptions")
+ && CHROME.is(browserName)) {
caps.put("goog:chromeOptions", caps.get("chromeOptions"));
}
- if (caps.containsKey("loggingPrefs") && !caps.containsKey("goog:loggingPrefs")) {
+ if (caps.containsKey("loggingPrefs") && !caps.containsKey("goog:loggingPrefs")
+ && CHROME.is(browserName)) {
caps.put("goog:loggingPrefs", caps.get("loggingPrefs"));
}
