Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Remove "se:bidi" #13528

Merged
merged 12 commits into from
Mar 26, 2024
10 changes: 2 additions & 8 deletions java/src/org/openqa/selenium/bidi/BiDiProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,8 @@ public HasBiDi getImplementation(Capabilities caps, ExecuteMethod executeMethod)
}

private Optional<URI> getBiDiUrl(Capabilities caps) {
Object bidiCapability;
if (caps.asMap().containsKey("se:bidi")) {
// Session is created remotely
bidiCapability = caps.getCapability("se:bidi");
} else {
bidiCapability = caps.getCapability("webSocketUrl");
}
Optional<String> webSocketUrl = Optional.ofNullable((String) bidiCapability);
Object biDiCapability = caps.getCapability("webSocketUrl");
Optional<String> webSocketUrl = Optional.ofNullable((String) biDiCapability);

return webSocketUrl.map(
uri -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private Optional<Consumer<Message>> findBiDiEndpoint(
Consumer<SessionId> sessionConsumer,
SessionId sessionId) {
try {
URI uri = new URI(String.valueOf(caps.getCapability("webSocketUrl")));
URI uri = new URI(String.valueOf(caps.getCapability("se:gridWebSocketUrl")));
return Optional.of(uri)
.map(bidi -> createWsEndPoint(bidi, downstream, sessionConsumer, sessionId));
} catch (URISyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.Duration;
import java.time.Instant;
Expand Down Expand Up @@ -186,7 +185,6 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
}

caps = readDevToolsEndpointAndVersion(caps);
caps = readBiDiEndpoint(caps);
caps = readVncEndpoint(capabilities, caps);

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

private Capabilities readBiDiEndpoint(Capabilities caps) {

Optional<String> webSocketUrl =
Optional.ofNullable((String) caps.getCapability("webSocketUrl"));

Optional<URI> websocketUri =
webSocketUrl.map(
uri -> {
try {
return new URI(uri);
} catch (URISyntaxException e) {
LOG.warning(e.getMessage());
}
return null;
});

if (websocketUri.isPresent()) {
return new PersistentCapabilities(caps).setCapability("se:bidi", websocketUri.get());
}

return caps;
}

private Capabilities readVncEndpoint(Capabilities requestedCaps, Capabilities returnedCaps) {
String seVncEnabledCap = "se:vncEnabled";
String seNoVncPortCap = "se:noVncPort";
Expand Down
28 changes: 21 additions & 7 deletions java/src/org/openqa/selenium/grid/node/local/LocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,20 +805,34 @@ private Session createExternalSession(
}

// Check if the user wants to use BiDi
boolean webSocketUrl = toUse.asMap().containsKey("webSocketUrl");
// Add se:bidi if necessary to send the bidi url back
boolean bidiSupported = isSupportingBiDi || toUse.getCapability("se:bidi") != null;
if (bidiSupported && bidiEnabled && webSocketUrl) {
// This will be null if the user has not set the capability.
Object webSocketUrl = toUse.getCapability("webSocketUrl");

// In case of Firefox versions that do not support webSocketUrl, it returns the capability as it
// is i.e. boolean value. So need to check if it is a string.
// Check if the Node supports BiDi and if the client wants to use BiDi.
boolean bidiSupported = isSupportingBiDi && (webSocketUrl instanceof String);
if (bidiSupported && bidiEnabled) {
String biDiUrl = (String) other.getCapabilities().getCapability("webSocketUrl");
pujagani marked this conversation as resolved.
Show resolved Hide resolved
URI uri = null;
try {
uri = new URI(biDiUrl);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Unable to create URI from " + uri);
}
String bidiPath = String.format("/session/%s/se/bidi", other.getId());
toUse = new PersistentCapabilities(toUse).setCapability("se:bidi", rewrite(bidiPath));
toUse =
new PersistentCapabilities(toUse)
.setCapability("se:gridWebSocketUrl", uri)
.setCapability("webSocketUrl", rewrite(bidiPath));
} else {
// Remove any se:bidi* from the response, BiDi is not supported nor enabled
// Remove any "webSocketUrl" from the response, BiDi is not supported nor enabled
MutableCapabilities bidiFiltered = new MutableCapabilities();
toUse
.asMap()
.forEach(
(key, value) -> {
if (!key.startsWith("se:bidi")) {
if (!key.startsWith("webSocketUrl")) {
bidiFiltered.setCapability(key, value);
}
});
Expand Down
Loading