Skip to content

Commit 5ebc0e6

Browse files
committed
[java] Fixing browser name and browser-specific capability prefix in EdgeFilter
1 parent 9ea1953 commit 5ebc0e6

9 files changed

Lines changed: 138 additions & 7 deletions

File tree

java/client/src/org/openqa/selenium/remote/session/ChromeFilter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package org.openqa.selenium.remote.session;
1919

20+
import org.openqa.selenium.remote.BrowserType;
21+
import org.openqa.selenium.remote.CapabilityType;
22+
2023
import java.util.Map;
2124
import java.util.Objects;
2225
import java.util.TreeMap;
@@ -28,7 +31,7 @@ public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
2831
Map<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
2932
.filter(
3033
entry ->
31-
("browserName".equals(entry.getKey()) && "chrome".equals(entry.getValue())) ||
34+
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.EDGE.equals(entry.getValue())) ||
3235
entry.getKey().startsWith("goog:") ||
3336
"chromeOptions".equals(entry.getKey()) ||
3437
"loggingPrefs".equals(entry.getKey()))

java/client/src/org/openqa/selenium/remote/session/EdgeFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import com.google.common.collect.ImmutableMap;
2121

22+
import org.openqa.selenium.remote.BrowserType;
23+
import org.openqa.selenium.remote.CapabilityType;
24+
2225
import java.util.Map;
2326
import java.util.Objects;
2427

@@ -27,7 +30,9 @@ public class EdgeFilter implements CapabilitiesFilter {
2730
@Override
2831
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
2932
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
30-
.filter(entry -> ("browserName".equals(entry.getKey()) && "edge".equals(entry.getValue())))
33+
.filter(
34+
entry -> (CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.EDGE.equals(entry.getValue())) ||
35+
entry.getKey().startsWith("ms:"))
3136
.distinct()
3237
.filter(entry -> Objects.nonNull(entry.getValue()))
3338
.collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));

java/client/src/org/openqa/selenium/remote/session/FirefoxFilter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package org.openqa.selenium.remote.session;
1919

20+
import org.openqa.selenium.remote.BrowserType;
21+
import org.openqa.selenium.remote.CapabilityType;
22+
2023
import java.util.Map;
2124
import java.util.Objects;
2225
import java.util.TreeMap;
@@ -29,7 +32,7 @@ public class FirefoxFilter implements CapabilitiesFilter {
2932
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
3033
Map<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
3134
.filter(entry ->
32-
("browserName".equals(entry.getKey()) && "firefox".equals(entry.getValue())) ||
35+
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.FIREFOX.equals(entry.getValue())) ||
3336
entry.getKey().startsWith("firefox_") ||
3437
entry.getKey().startsWith("moz:"))
3538
.filter(entry -> Objects.nonNull(entry.getValue()))

java/client/src/org/openqa/selenium/remote/session/InternetExplorerFilter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import com.google.common.collect.ImmutableMap;
2121

22+
import org.openqa.selenium.remote.BrowserType;
23+
import org.openqa.selenium.remote.CapabilityType;
24+
2225
import java.util.Map;
2326
import java.util.Objects;
2427

@@ -27,7 +30,7 @@ public class InternetExplorerFilter implements CapabilitiesFilter {
2730
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
2831
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
2932
.filter(entry ->
30-
("browserName".equals(entry.getKey()) && "internet explorer".equals(entry.getValue())) ||
33+
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.IE.equals(entry.getValue())) ||
3134
"browserAttachTimeout".equals(entry.getKey()) ||
3235
"enableElementCacheCleanup".equals(entry.getKey()) ||
3336
"enablePersistentHover".equals(entry.getKey()) ||

java/client/src/org/openqa/selenium/remote/session/OperaFilter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import com.google.common.collect.ImmutableMap;
2121

22+
import org.openqa.selenium.remote.BrowserType;
23+
import org.openqa.selenium.remote.CapabilityType;
24+
2225
import java.util.Map;
2326
import java.util.Objects;
2427

@@ -27,8 +30,8 @@ public class OperaFilter implements CapabilitiesFilter {
2730
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
2831
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
2932
.filter(entry ->
30-
("browserName".equals(entry.getKey()) && "opera".equals(entry.getValue())) ||
31-
("browserName".equals(entry.getKey()) && "operablink".equals(entry.getValue())) ||
33+
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.OPERA.equals(entry.getValue())) ||
34+
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.OPERA_BLINK.equals(entry.getValue())) ||
3235
"operaOptions".equals(entry.getKey()))
3336
.distinct()
3437
.filter(entry -> Objects.nonNull(entry.getValue()))

java/client/src/org/openqa/selenium/remote/session/SafariFilter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import com.google.common.collect.ImmutableMap;
2121

22+
import org.openqa.selenium.remote.BrowserType;
23+
import org.openqa.selenium.remote.CapabilityType;
24+
2225
import java.util.Map;
2326
import java.util.Objects;
2427

@@ -27,7 +30,7 @@ public class SafariFilter implements CapabilitiesFilter {
2730
public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
2831
ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream()
2932
.filter(entry ->
30-
("browserName".equals(entry.getKey()) && "safari".equals(entry.getValue())) ||
33+
(CapabilityType.BROWSER_NAME.equals(entry.getKey()) && BrowserType.SAFARI.equals(entry.getValue())) ||
3134
"safari.options".equals(entry.getKey()))
3235
.distinct()
3336
.filter(entry -> Objects.nonNull(entry.getValue()))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//java:defs.bzl", "java_test_suite")
3+
4+
java_test_suite(
5+
name = "small-tests",
6+
size = "small",
7+
srcs = glob(["*.java"]),
8+
deps = [
9+
"//java/client/src/org/openqa/selenium/chrome",
10+
"//java/client/src/org/openqa/selenium/edge",
11+
"//java/client/src/org/openqa/selenium/remote",
12+
"//java/client/test/org/openqa/selenium/testing:annotations",
13+
artifact("junit:junit"),
14+
artifact("org.assertj:assertj-core"),
15+
artifact("org.mockito:mockito-core"),
16+
],
17+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.remote.session;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
22+
import org.junit.Test;
23+
import org.junit.experimental.categories.Category;
24+
import org.openqa.selenium.chrome.ChromeOptions;
25+
import org.openqa.selenium.edge.EdgeOptions;
26+
import org.openqa.selenium.testing.UnitTests;
27+
28+
import java.util.Map;
29+
30+
@Category(UnitTests.class)
31+
public class ChromeFilterTest {
32+
33+
@Test
34+
public void shouldNotFilterOutChromeCapabilities() {
35+
Map<String, Object> original = new ChromeOptions().asMap();
36+
Map<String, Object> filtered = new ChromeFilter().apply(original);
37+
assertThat(filtered).isEqualTo(original);
38+
}
39+
40+
@Test
41+
public void shouldFilterOutNonChromeCapabilities() {
42+
Map<String, Object> original = new EdgeOptions().asMap();
43+
Map<String, Object> filtered = new ChromeFilter().apply(original);
44+
assertThat(filtered).isNull();
45+
}
46+
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.remote.session;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
22+
import org.junit.Test;
23+
import org.junit.experimental.categories.Category;
24+
import org.openqa.selenium.chrome.ChromeOptions;
25+
import org.openqa.selenium.edge.EdgeOptions;
26+
import org.openqa.selenium.testing.UnitTests;
27+
28+
import java.util.Map;
29+
30+
@Category(UnitTests.class)
31+
public class EdgeFilterTest {
32+
33+
@Test
34+
public void shouldNotFilterOutEdgeCapabilities() {
35+
Map<String, Object> original = new EdgeOptions().asMap();
36+
Map<String, Object> filtered = new EdgeFilter().apply(original);
37+
assertThat(filtered).isEqualTo(original);
38+
}
39+
40+
@Test
41+
public void shouldFilterOutNonEdgeCapabilities() {
42+
Map<String, Object> original = new ChromeOptions().asMap();
43+
Map<String, Object> filtered = new EdgeFilter().apply(original);
44+
assertThat(filtered).isNull();
45+
}
46+
47+
}

0 commit comments

Comments
 (0)