Skip to content

Commit 1fe43fa

Browse files
committed
[grid] Forward BiDi from node to driver
1 parent e6bd1f8 commit 1fe43fa

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

java/src/org/openqa/selenium/grid/node/ProxyNodeWebsockets.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class ProxyNodeWebsockets implements BiFunction<String, Consumer<Message>
5050
Optional<Consumer<Message>>> {
5151

5252
private static final UrlTemplate CDP_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/cdp");
53+
private static final UrlTemplate BIDI_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/bidi");
5354
private static final UrlTemplate FWD_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/fwd");
5455
private static final UrlTemplate VNC_TEMPLATE = new UrlTemplate("/session/{sessionId}/se/vnc");
5556
private static final Logger LOG = Logger.getLogger(ProxyNodeWebsockets.class.getName());
@@ -70,13 +71,14 @@ public ProxyNodeWebsockets(HttpClient.Factory clientFactory, Node node) {
7071
public Optional<Consumer<Message>> apply(String uri, Consumer<Message> downstream) {
7172
UrlTemplate.Match fwdMatch = FWD_TEMPLATE.match(uri);
7273
UrlTemplate.Match cdpMatch = CDP_TEMPLATE.match(uri);
74+
UrlTemplate.Match bidiMatch = BIDI_TEMPLATE.match(uri);
7375
UrlTemplate.Match vncMatch = VNC_TEMPLATE.match(uri);
7476

7577
if (cdpMatch == null && vncMatch == null && fwdMatch == null) {
7678
return Optional.empty();
7779
}
7880

79-
String sessionId = Stream.of(fwdMatch, cdpMatch, vncMatch)
81+
String sessionId = Stream.of(fwdMatch, cdpMatch, bidiMatch, vncMatch)
8082
.filter(Objects::nonNull)
8183
.findFirst()
8284
.get()
@@ -95,6 +97,10 @@ public Optional<Consumer<Message>> apply(String uri, Consumer<Message> downstrea
9597
Capabilities caps = session.getCapabilities();
9698
LOG.fine("Scanning for endpoint: " + caps);
9799

100+
if (bidiMatch != null) {
101+
return findBiDiEndpoint(downstream, caps);
102+
}
103+
98104
if (vncMatch != null) {
99105
return findVncEndpoint(downstream, caps);
100106
}
@@ -125,6 +131,16 @@ private Optional<Consumer<Message>> findCdpEndpoint(Consumer<Message> downstream
125131
return Optional.empty();
126132
}
127133

134+
private Optional<Consumer<Message>> findBiDiEndpoint(Consumer<Message> downstream, Capabilities caps) {
135+
try {
136+
URI uri = new URI(String.valueOf(caps.getCapability("webSocketUrl")));
137+
return Optional.of(uri).map(bidi -> createWsEndPoint(bidi, downstream));
138+
} catch (URISyntaxException e) {
139+
LOG.warning("Unable to create URI from: " + caps.getCapability(""));
140+
return Optional.empty();
141+
}
142+
}
143+
128144
private Optional<Consumer<Message>> findForwardCdpEndpoint(Consumer<Message> downstream,
129145
Capabilities caps) {
130146
// When using Dynamic Grid, we need to connect to a container before using the debuggerAddress

0 commit comments

Comments
 (0)