Skip to content

Commit

Permalink
[java] Fixing browser name and browser-specific capability prefix in …
Browse files Browse the repository at this point in the history
…EdgeFilter
  • Loading branch information
barancev committed Feb 23, 2021
1 parent 9ea1953 commit 5ebc0e6
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.openqa.selenium.remote.session;

import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
Expand All @@ -28,7 +31,7 @@ public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
Map<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
.filter(
entry ->
("browserName".equals(entry.getKey()) && "chrome".equals(entry.getValue())) ||
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.EDGE.equals(entry.getValue())) ||
entry.getKey().startsWith("goog:") ||
"chromeOptions".equals(entry.getKey()) ||
"loggingPrefs".equals(entry.getKey()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Map;
import java.util.Objects;

Expand All @@ -27,7 +30,9 @@ public class EdgeFilter implements CapabilitiesFilter {
@Override
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
.filter(entry -> ("browserName".equals(entry.getKey()) && "edge".equals(entry.getValue())))
.filter(
entry -> (CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.EDGE.equals(entry.getValue())) ||
entry.getKey().startsWith("ms:"))
.distinct()
.filter(entry -> Objects.nonNull(entry.getValue()))
.collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.openqa.selenium.remote.session;

import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
Expand All @@ -29,7 +32,7 @@ public class FirefoxFilter implements CapabilitiesFilter {
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
Map<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
.filter(entry ->
("browserName".equals(entry.getKey()) && "firefox".equals(entry.getValue())) ||
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.FIREFOX.equals(entry.getValue())) ||
entry.getKey().startsWith("firefox_") ||
entry.getKey().startsWith("moz:"))
.filter(entry -> Objects.nonNull(entry.getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Map;
import java.util.Objects;

Expand All @@ -27,7 +30,7 @@ public class InternetExplorerFilter implements CapabilitiesFilter {
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
.filter(entry ->
("browserName".equals(entry.getKey()) && "internet explorer".equals(entry.getValue())) ||
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.IE.equals(entry.getValue())) ||
"browserAttachTimeout".equals(entry.getKey()) ||
"enableElementCacheCleanup".equals(entry.getKey()) ||
"enablePersistentHover".equals(entry.getKey()) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Map;
import java.util.Objects;

Expand All @@ -27,8 +30,8 @@ public class OperaFilter implements CapabilitiesFilter {
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
.filter(entry ->
("browserName".equals(entry.getKey()) && "opera".equals(entry.getValue())) ||
("browserName".equals(entry.getKey()) && "operablink".equals(entry.getValue())) ||
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.OPERA.equals(entry.getValue())) ||
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.OPERA_BLINK.equals(entry.getValue())) ||
"operaOptions".equals(entry.getKey()))
.distinct()
.filter(entry -> Objects.nonNull(entry.getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Map;
import java.util.Objects;

Expand All @@ -27,7 +30,7 @@ public class SafariFilter implements CapabilitiesFilter {
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
.filter(entry ->
("browserName".equals(entry.getKey()) && "safari".equals(entry.getValue())) ||
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.SAFARI.equals(entry.getValue())) ||
"safari.options".equals(entry.getKey()))
.distinct()
.filter(entry -> Objects.nonNull(entry.getValue()))
Expand Down
17 changes: 17 additions & 0 deletions java/client/test/org/openqa/selenium/remote/session/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_test_suite")

java_test_suite(
name = "small-tests",
size = "small",
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/chrome",
"//java/client/src/org/openqa/selenium/edge",
"//java/client/src/org/openqa/selenium/remote",
"//java/client/test/org/openqa/selenium/testing:annotations",
artifact("junit:junit"),
artifact("org.assertj:assertj-core"),
artifact("org.mockito:mockito-core"),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.session;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.testing.UnitTests;

import java.util.Map;

@Category(UnitTests.class)
public class ChromeFilterTest {

@Test
public void shouldNotFilterOutChromeCapabilities() {
Map<String, Object> original = new ChromeOptions().asMap();
Map<String, Object> filtered = new ChromeFilter().apply(original);
assertThat(filtered).isEqualTo(original);
}

@Test
public void shouldFilterOutNonChromeCapabilities() {
Map<String, Object> original = new EdgeOptions().asMap();
Map<String, Object> filtered = new ChromeFilter().apply(original);
assertThat(filtered).isNull();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.session;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.testing.UnitTests;

import java.util.Map;

@Category(UnitTests.class)
public class EdgeFilterTest {

@Test
public void shouldNotFilterOutEdgeCapabilities() {
Map<String, Object> original = new EdgeOptions().asMap();
Map<String, Object> filtered = new EdgeFilter().apply(original);
assertThat(filtered).isEqualTo(original);
}

@Test
public void shouldFilterOutNonEdgeCapabilities() {
Map<String, Object> original = new ChromeOptions().asMap();
Map<String, Object> filtered = new EdgeFilter().apply(original);
assertThat(filtered).isNull();
}

}

0 comments on commit 5ebc0e6

Please sign in to comment.