Skip to content

Commit 907b219

Browse files
pujaganidiemol
andauthored
[java] Remove "se:bidi" (#13528)
* [java] Remove "se:bidi" * Add comments * Format code * [java] Store "local" websocket url in a different namespace and use it * [java] Fix websocket url checks * [java] Keep /se/bidi intact --------- Co-authored-by: Diego Molina <[email protected]>
1 parent 55e7a53 commit 907b219

File tree

4 files changed

+24
-41
lines changed

4 files changed

+24
-41
lines changed

java/src/org/openqa/selenium/bidi/BiDiProvider.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ public HasBiDi getImplementation(Capabilities caps, ExecuteMethod executeMethod)
5656
}
5757

5858
private Optional<URI> getBiDiUrl(Capabilities caps) {
59-
Object bidiCapability;
60-
if (caps.asMap().containsKey("se:bidi")) {
61-
// Session is created remotely
62-
bidiCapability = caps.getCapability("se:bidi");
63-
} else {
64-
bidiCapability = caps.getCapability("webSocketUrl");
65-
}
66-
Optional<String> webSocketUrl = Optional.ofNullable((String) bidiCapability);
59+
Object biDiCapability = caps.getCapability("webSocketUrl");
60+
Optional<String> webSocketUrl = Optional.ofNullable((String) biDiCapability);
6761

6862
return webSocketUrl.map(
6963
uri -> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private Optional<Consumer<Message>> findBiDiEndpoint(
171171
Consumer<SessionId> sessionConsumer,
172172
SessionId sessionId) {
173173
try {
174-
URI uri = new URI(String.valueOf(caps.getCapability("webSocketUrl")));
174+
URI uri = new URI(String.valueOf(caps.getCapability("se:gridWebSocketUrl")));
175175
return Optional.of(uri)
176176
.map(bidi -> createWsEndPoint(bidi, downstream, sessionConsumer, sessionId));
177177
} catch (URISyntaxException e) {

java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
2323

2424
import java.net.URI;
25-
import java.net.URISyntaxException;
2625
import java.net.URL;
2726
import java.time.Duration;
2827
import java.time.Instant;
@@ -186,7 +185,6 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
186185
}
187186

188187
caps = readDevToolsEndpointAndVersion(caps);
189-
caps = readBiDiEndpoint(caps);
190188
caps = readVncEndpoint(capabilities, caps);
191189

192190
span.addEvent("Driver service created session", attributeMap);
@@ -281,29 +279,6 @@ public DevToolsInfo(URI cdpEndpoint, String version) {
281279
return caps;
282280
}
283281

284-
private Capabilities readBiDiEndpoint(Capabilities caps) {
285-
286-
Optional<String> webSocketUrl =
287-
Optional.ofNullable((String) caps.getCapability("webSocketUrl"));
288-
289-
Optional<URI> websocketUri =
290-
webSocketUrl.map(
291-
uri -> {
292-
try {
293-
return new URI(uri);
294-
} catch (URISyntaxException e) {
295-
LOG.warning(e.getMessage());
296-
}
297-
return null;
298-
});
299-
300-
if (websocketUri.isPresent()) {
301-
return new PersistentCapabilities(caps).setCapability("se:bidi", websocketUri.get());
302-
}
303-
304-
return caps;
305-
}
306-
307282
private Capabilities readVncEndpoint(Capabilities requestedCaps, Capabilities returnedCaps) {
308283
String seVncEnabledCap = "se:vncEnabled";
309284
String seNoVncPortCap = "se:noVncPort";

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,20 +805,34 @@ private Session createExternalSession(
805805
}
806806

807807
// Check if the user wants to use BiDi
808-
boolean webSocketUrl = toUse.asMap().containsKey("webSocketUrl");
809-
// Add se:bidi if necessary to send the bidi url back
810-
boolean bidiSupported = isSupportingBiDi || toUse.getCapability("se:bidi") != null;
811-
if (bidiSupported && bidiEnabled && webSocketUrl) {
808+
// This will be null if the user has not set the capability.
809+
Object webSocketUrl = toUse.getCapability("webSocketUrl");
810+
811+
// In case of Firefox versions that do not support webSocketUrl, it returns the capability as it
812+
// is i.e. boolean value. So need to check if it is a string.
813+
// Check if the Node supports BiDi and if the client wants to use BiDi.
814+
boolean bidiSupported = isSupportingBiDi && (webSocketUrl instanceof String);
815+
if (bidiSupported && bidiEnabled) {
816+
String biDiUrl = (String) other.getCapabilities().getCapability("webSocketUrl");
817+
URI uri = null;
818+
try {
819+
uri = new URI(biDiUrl);
820+
} catch (URISyntaxException e) {
821+
throw new IllegalArgumentException("Unable to create URI from " + uri);
822+
}
812823
String bidiPath = String.format("/session/%s/se/bidi", other.getId());
813-
toUse = new PersistentCapabilities(toUse).setCapability("se:bidi", rewrite(bidiPath));
824+
toUse =
825+
new PersistentCapabilities(toUse)
826+
.setCapability("se:gridWebSocketUrl", uri)
827+
.setCapability("webSocketUrl", rewrite(bidiPath));
814828
} else {
815-
// Remove any se:bidi* from the response, BiDi is not supported nor enabled
829+
// Remove any "webSocketUrl" from the response, BiDi is not supported nor enabled
816830
MutableCapabilities bidiFiltered = new MutableCapabilities();
817831
toUse
818832
.asMap()
819833
.forEach(
820834
(key, value) -> {
821-
if (!key.startsWith("se:bidi")) {
835+
if (!key.startsWith("webSocketUrl")) {
822836
bidiFiltered.setCapability(key, value);
823837
}
824838
});

0 commit comments

Comments
 (0)