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

[grid] Dynamic Grid is able to trigger video record in browser node #15047

Merged
merged 4 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading