Skip to content

Commit

Permalink
[grid] Enabling live view for Dynamic Grid
Browse files Browse the repository at this point in the history
We were hardcoding 'localhost', which works
in most of the cases, but when Dynamic Grid
is used, the stream needs to be routed once
more, and for that, we can use the container
IP.
  • Loading branch information
diemol committed Sep 16, 2021
1 parent 04c1209 commit ca58c3b
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.openqa.selenium.grid.node.config;

import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES_EVENT;
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.PersistentCapabilities;
Expand All @@ -30,6 +34,8 @@
import org.openqa.selenium.grid.node.SessionFactory;
import org.openqa.selenium.internal.Either;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.net.HostIdentifier;
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.Dialect;
import org.openqa.selenium.remote.DriverCommand;
Expand All @@ -56,10 +62,6 @@
import java.util.function.Predicate;
import java.util.stream.Stream;

import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES_EVENT;
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;

public class DriverServiceSessionFactory implements SessionFactory {

private final Tracer tracer;
Expand Down Expand Up @@ -227,9 +229,11 @@ public DevToolsInfo(URI cdpEndpoint, String version) {
private Capabilities readVncEndpoint(Capabilities requestedCaps, Capabilities returnedCaps) {
String seVncEnabledCap = "se:vncEnabled";
String seVncEnabled = String.valueOf(requestedCaps.getCapability(seVncEnabledCap));
if (Boolean.parseBoolean(seVncEnabled)) {
boolean vncLocalAddressSet = requestedCaps.getCapabilityNames().contains("se:vncLocalAddress");
if (Boolean.parseBoolean(seVncEnabled) && !vncLocalAddressSet) {
String vncLocalAddress = String.format("ws://%s:7900", getHost());
returnedCaps = new PersistentCapabilities(returnedCaps)
.setCapability("se:vncLocalAddress", "ws://localhost:7900/websockify")
.setCapability("se:vncLocalAddress", vncLocalAddress)
.setCapability(seVncEnabledCap, true);
}
return returnedCaps;
Expand All @@ -244,4 +248,13 @@ private Capabilities generalizePlatform(Capabilities caps) {
private Capabilities setInitialPlatform(Capabilities caps, Platform platform) {
return new PersistentCapabilities(caps).setCapability("platformName", platform);
}

private String getHost() {
try {
return new NetworkUtils().getNonLoopbackAddressOfThisMachine();
} catch (WebDriverException e) {
return HostIdentifier.getHostName();
}

}
}

0 comments on commit ca58c3b

Please sign in to comment.