Skip to content

Commit

Permalink
[java] Making sure "loggingPrefs" only affects Chrome
Browse files Browse the repository at this point in the history
Fixes #10222
  • Loading branch information
diemol committed May 30, 2022
1 parent 3334607 commit c8da7c2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions java/src/org/openqa/selenium/remote/session/ChromeFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<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(
Expand All @@ -45,11 +45,13 @@ public Map<String, Object> apply(Map<String, Object> 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"));
}

Expand Down

0 comments on commit c8da7c2

Please sign in to comment.