diff --git a/.gitignore b/.gitignore
index 78a19f71f3a6d2..0415d80bc86c1b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -135,3 +135,4 @@ bazel-testlogs
javascript/node/selenium-webdriver/.vscode/settings.json
dotnet-bin
+.metadata/
diff --git a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java
index 628d66088f9160..9e518401b8dabd 100644
--- a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java
+++ b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java
@@ -89,7 +89,6 @@
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.ConnectionFailedException;
import org.openqa.selenium.remote.http.HttpClient;
-import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
import org.openqa.selenium.remote.tracing.TracedHttpClient;
import org.openqa.selenium.remote.tracing.Tracer;
import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;
diff --git a/java/src/org/openqa/selenium/remote/WebElementToJsonConverter.java b/java/src/org/openqa/selenium/remote/WebElementToJsonConverter.java
new file mode 100644
index 00000000000000..edb4c9a28d9cb5
--- /dev/null
+++ b/java/src/org/openqa/selenium/remote/WebElementToJsonConverter.java
@@ -0,0 +1,93 @@
+// 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;
+
+import static java.util.stream.Collectors.toList;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import org.openqa.selenium.WrapsElement;
+
+/**
+ * Converts {@link RemoteWebElement} objects, which may be {@link WrapsElement wrapped}, into their
+ * JSON representation as defined by the WebDriver wire protocol. This class will recursively
+ * convert Lists and Maps to catch nested references.
+ *
+ * @see
+ * WebDriver JSON Wire Protocol
+ */
+public class WebElementToJsonConverter implements Function {
+ @Override
+ public Object apply(Object arg) {
+ if (arg == null || arg instanceof String || arg instanceof Boolean || arg instanceof Number) {
+ return arg;
+ }
+
+ while (arg instanceof WrapsElement) {
+ arg = ((WrapsElement) arg).getWrappedElement();
+ }
+
+ if (arg instanceof RemoteWebElement) {
+ return Map.of(Dialect.W3C.getEncodedElementKey(), ((RemoteWebElement) arg).getId());
+ }
+
+ if (arg instanceof ShadowRoot) {
+ return Map.of(Dialect.W3C.getShadowRootElementKey(), ((ShadowRoot) arg).getId());
+ }
+
+ if (arg.getClass().isArray()) {
+ arg = arrayToList(arg);
+ }
+
+ if (arg instanceof Collection>) {
+ Collection> args = (Collection>) arg;
+ return args.stream().map(this).collect(toList());
+ }
+
+ if (arg instanceof Map, ?>) {
+ Map, ?> args = (Map, ?>) arg;
+ Map converted = new HashMap<>(args.size());
+ for (Map.Entry, ?> entry : args.entrySet()) {
+ Object key = entry.getKey();
+ if (!(key instanceof String)) {
+ throw new IllegalArgumentException(
+ "All keys in Map script arguments must be strings: " + key.getClass().getName());
+ }
+ converted.put((String) key, apply(entry.getValue()));
+ }
+ return converted;
+ }
+
+ throw new IllegalArgumentException(
+ "Argument is of an illegal type: " + arg.getClass().getName());
+ }
+
+ private static List arrayToList(Object array) {
+ List list = new ArrayList<>();
+ for (int i = 0; i < Array.getLength(array); i++) {
+ list.add(Array.get(array, i));
+ }
+ return list;
+ }
+}
diff --git a/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec.java b/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec.java
index 8efb17fb3bf7c5..23edf90a0cb397 100644
--- a/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec.java
+++ b/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec.java
@@ -89,7 +89,7 @@
import org.openqa.selenium.InvalidSelectorException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.codec.AbstractHttpCommandCodec;
-import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
+import org.openqa.selenium.remote.WebElementToJsonConverter;
/**
* A command codec that adheres to the W3C's WebDriver wire protocol.
diff --git a/java/src/org/openqa/selenium/remote/internal/WebElementToJsonConverter.java b/java/src/org/openqa/selenium/remote/internal/WebElementToJsonConverter.java
index 19d55adeb36971..c2ffeebc154f08 100644
--- a/java/src/org/openqa/selenium/remote/internal/WebElementToJsonConverter.java
+++ b/java/src/org/openqa/selenium/remote/internal/WebElementToJsonConverter.java
@@ -17,75 +17,9 @@
package org.openqa.selenium.remote.internal;
-import static java.util.stream.Collectors.toList;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import org.openqa.selenium.WrapsElement;
-import org.openqa.selenium.remote.Dialect;
-import org.openqa.selenium.remote.RemoteWebElement;
-
/**
- * Converts {@link RemoteWebElement} objects, which may be {@link WrapsElement wrapped}, into their
- * JSON representation as defined by the WebDriver wire protocol. This class will recursively
- * convert Lists and Maps to catch nested references.
- *
- * @see
- * WebDriver JSON Wire Protocol
+ * {@inheritDoc}
+ * @deprecated This class has moved to a {@link org.openqa.selenium.remote.WebElementToJsonConverter new location}.
*/
-public class WebElementToJsonConverter implements Function {
- @Override
- public Object apply(Object arg) {
- if (arg == null || arg instanceof String || arg instanceof Boolean || arg instanceof Number) {
- return arg;
- }
-
- while (arg instanceof WrapsElement) {
- arg = ((WrapsElement) arg).getWrappedElement();
- }
-
- if (arg instanceof RemoteWebElement) {
- return Map.of(Dialect.W3C.getEncodedElementKey(), ((RemoteWebElement) arg).getId());
- }
-
- if (arg.getClass().isArray()) {
- arg = arrayToList(arg);
- }
-
- if (arg instanceof Collection>) {
- Collection> args = (Collection>) arg;
- return args.stream().map(this).collect(toList());
- }
-
- if (arg instanceof Map, ?>) {
- Map, ?> args = (Map, ?>) arg;
- Map converted = new HashMap<>(args.size());
- for (Map.Entry, ?> entry : args.entrySet()) {
- Object key = entry.getKey();
- if (!(key instanceof String)) {
- throw new IllegalArgumentException(
- "All keys in Map script arguments must be strings: " + key.getClass().getName());
- }
- converted.put((String) key, apply(entry.getValue()));
- }
- return converted;
- }
-
- throw new IllegalArgumentException(
- "Argument is of an illegal type: " + arg.getClass().getName());
- }
-
- private static List arrayToList(Object array) {
- List list = new ArrayList<>();
- for (int i = 0; i < Array.getLength(array); i++) {
- list.add(Array.get(array, i));
- }
- return list;
- }
+public class WebElementToJsonConverter extends org.openqa.selenium.remote.WebElementToJsonConverter {
}
diff --git a/java/test/org/openqa/selenium/remote/BUILD.bazel b/java/test/org/openqa/selenium/remote/BUILD.bazel
index 91d95e58f98c74..5f889931ed207f 100644
--- a/java/test/org/openqa/selenium/remote/BUILD.bazel
+++ b/java/test/org/openqa/selenium/remote/BUILD.bazel
@@ -29,6 +29,7 @@ java_test_suite(
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/support",
+ "//java/test/org/openqa/selenium:helpers",
"//java/test/org/openqa/selenium/testing:annotations",
artifact("org.assertj:assertj-core"),
artifact("com.google.guava:guava"),
diff --git a/java/test/org/openqa/selenium/remote/internal/WebElementToJsonConverterTest.java b/java/test/org/openqa/selenium/remote/WebElementToJsonConverterTest.java
similarity index 91%
rename from java/test/org/openqa/selenium/remote/internal/WebElementToJsonConverterTest.java
rename to java/test/org/openqa/selenium/remote/WebElementToJsonConverterTest.java
index 42eee6f63b6d89..31e9aaaa14e89a 100644
--- a/java/test/org/openqa/selenium/remote/internal/WebElementToJsonConverterTest.java
+++ b/java/test/org/openqa/selenium/remote/WebElementToJsonConverterTest.java
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-package org.openqa.selenium.remote.internal;
+package org.openqa.selenium.remote;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,10 +27,10 @@
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
+import org.openqa.selenium.Capabilities;
+import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WrappedWebElement;
-import org.openqa.selenium.remote.Dialect;
-import org.openqa.selenium.remote.RemoteWebElement;
class WebElementToJsonConverterTest {
@@ -218,6 +218,15 @@ void convertsAnArrayWithAWebElement() {
ImmutableMap.of(Dialect.W3C.getEncodedElementKey(), "abc123"));
}
+ @Test
+ void shouldConvertShadowRoots() {
+ ShadowRoot context = new ShadowRoot(createIdleDriver(), "abc123");
+ Object value = CONVERTER.apply(new Object[] {context});
+ assertContentsInOrder(
+ new ArrayList<>((Collection>) value),
+ ImmutableMap.of(Dialect.W3C.getShadowRootElementKey(), "abc123"));
+ }
+
private static WrappedWebElement wrapElement(WebElement element) {
return new WrappedWebElement(element);
}
@@ -235,4 +244,13 @@ private static void assertContentsInOrder(List> list, Object... expectedConten
List expected = asList(expectedContents);
assertThat(list).isEqualTo(expected);
}
+
+ private static RemoteWebDriver createIdleDriver() {
+ return new RemoteWebDriver(cmd -> new Response(), new ImmutableCapabilities()) {
+ @Override
+ protected void startSession(Capabilities capabilities) {
+ // Do nothing
+ }
+ };
+ }
}
diff --git a/java/test/org/openqa/selenium/remote/internal/BUILD.bazel b/java/test/org/openqa/selenium/remote/internal/BUILD.bazel
index cc734053308658..f11c60447353c2 100644
--- a/java/test/org/openqa/selenium/remote/internal/BUILD.bazel
+++ b/java/test/org/openqa/selenium/remote/internal/BUILD.bazel
@@ -30,22 +30,3 @@ java_library(
artifact("io.netty:netty-transport"),
] + JUNIT5_DEPS,
)
-
-java_test_suite(
- name = "SmallTests",
- size = "small",
- srcs = glob(["*Test.java"]),
- tags = [
- "no-sandbox",
- ],
- deps = [
- ":test-lib",
- "//java/src/org/openqa/selenium:core",
- "//java/src/org/openqa/selenium/remote",
- "//java/src/org/openqa/selenium/remote/http",
- "//java/test/org/openqa/selenium:helpers",
- artifact("org.assertj:assertj-core"),
- artifact("com.google.guava:guava"),
- artifact("org.junit.jupiter:junit-jupiter-api"),
- ] + JUNIT5_DEPS,
-)
diff --git a/java/test/org/openqa/selenium/support/pagefactory/UsingPageFactoryTest.java b/java/test/org/openqa/selenium/support/pagefactory/UsingPageFactoryTest.java
index a3c578cd5a11e3..0954c3b331d6bc 100644
--- a/java/test/org/openqa/selenium/support/pagefactory/UsingPageFactoryTest.java
+++ b/java/test/org/openqa/selenium/support/pagefactory/UsingPageFactoryTest.java
@@ -27,7 +27,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;
-import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
+import org.openqa.selenium.remote.WebElementToJsonConverter;
import org.openqa.selenium.support.ByIdOrName;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;