Skip to content

Commit

Permalink
[grid] Dynamic Grid is able to trigger video record in browser node (S…
Browse files Browse the repository at this point in the history
…eleniumHQ#15047)

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Jan 12, 2025
1 parent e4b1e48 commit 928833e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public DockerAssetsPath(String hostPath, String containerPath) {
this.containerPath = containerPath;
}

public String getHostPath() {
return this.hostPath;
}

public String getHostPath(SessionId id) {
return this.hostPath + File.separator + id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class DockerOptions {
static final String DOCKER_SECTION = "docker";
static final String DEFAULT_ASSETS_PATH = "/opt/selenium/assets";
static final String DEFAULT_DOCKER_URL = "unix:/var/run/docker.sock";
static final String DEFAULT_VIDEO_IMAGE = "selenium/video:latest";
static final String DEFAULT_VIDEO_IMAGE = "false";
static final int DEFAULT_MAX_SESSIONS = Runtime.getRuntime().availableProcessors();
private static final String DEFAULT_DOCKER_NETWORK = "bridge";
private static final Logger LOG = Logger.getLogger(DockerOptions.class.getName());
Expand Down Expand Up @@ -159,7 +159,9 @@ public Map<Capabilities, Collection<SessionFactory>> getDockerSessionFactories(

loadImages(docker, kinds.keySet().toArray(new String[0]));
Image videoImage = getVideoImage(docker);
loadImages(docker, videoImage.getName());
if (videoImage != null) {
loadImages(docker, videoImage.getName());
}

// Hard coding the config section value "node" to avoid an extra dependency
int maxContainerCount =
Expand Down Expand Up @@ -224,6 +226,9 @@ protected List<Device> getDevicesMapping() {

private Image getVideoImage(Docker docker) {
String videoImage = config.get(DOCKER_SECTION, "video-image").orElse(DEFAULT_VIDEO_IMAGE);
if (videoImage.equalsIgnoreCase("false")) {
return null;
}
return docker.getImage(videoImage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,15 @@ private Capabilities addForwardCdpEndpoint(
}

private Container createBrowserContainer(int port, Capabilities sessionCapabilities) {
Map<String, String> browserContainerEnvVars = getBrowserContainerEnvVars(sessionCapabilities);
Map<String, String> browserContainerEnvVars = new HashMap<>();
// Enable env var to trigger video recording if session capabilities request and external video
// container is disabled
if (videoImage == null && recordVideoForSession(sessionCapabilities)) {
browserContainerEnvVars.put("SE_RECORD_VIDEO", "true");
browserContainerEnvVars.put("SE_VIDEO_FILE_NAME", "auto");
browserContainerEnvVars.put("SE_VIDEO_RECORD_STANDALONE", "true");
}
browserContainerEnvVars.putAll(getBrowserContainerEnvVars(sessionCapabilities));
long browserContainerShmMemorySize = 2147483648L; // 2GB
ContainerConfig containerConfig =
image(browserImage)
Expand All @@ -295,6 +303,10 @@ private Container createBrowserContainer(int port, Capabilities sessionCapabilit
.network(networkName)
.devices(devices)
.applyHostConfig(hostConfig, hostConfigKeys);
Optional<DockerAssetsPath> path = ofNullable(this.assetsPath);
if (path.isPresent() && videoImage == null && recordVideoForSession(sessionCapabilities)) {
containerConfig.bind(Collections.singletonMap(this.assetsPath.getHostPath(), "/videos"));
}
if (!runningInDocker) {
containerConfig = containerConfig.map(Port.tcp(4444), Port.tcp(port));
}
Expand Down Expand Up @@ -335,7 +347,7 @@ private void setCapsToEnvVars(

private Container startVideoContainer(
Capabilities sessionCapabilities, String browserContainerIp, String hostPath) {
if (!recordVideoForSession(sessionCapabilities)) {
if (videoImage == null || !recordVideoForSession(sessionCapabilities)) {
return null;
}
int videoPort = 9000;
Expand Down

0 comments on commit 928833e

Please sign in to comment.