From c8da7c2d2ad3c2b8204da063b96465ce4e0dc283 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Mon, 30 May 2022 14:47:05 +0200 Subject: [PATCH] [java] Making sure "loggingPrefs" only affects Chrome Fixes #10222 --- .../selenium/remote/session/ChromeFilter.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/session/ChromeFilter.java b/java/src/org/openqa/selenium/remote/session/ChromeFilter.java index c0666f79bf0d9..41c9caee8b976 100644 --- a/java/src/org/openqa/selenium/remote/session/ChromeFilter.java +++ b/java/src/org/openqa/selenium/remote/session/ChromeFilter.java @@ -17,25 +17,25 @@ 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 apply(Map unmodifiedCaps) { + String browserName = (String) unmodifiedCaps.getOrDefault(BROWSER_NAME, ""); Map 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( @@ -45,11 +45,13 @@ public Map apply(Map unmodifiedCaps) { 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")); }