Skip to content

Commit fdb58fb

Browse files
authored
Do not mount Selenium's SHM on Windows (#5105)
It looks like mounting /dev/shm did not play well on WSL2. This change uses Docker's SHM support on Windows.
1 parent 55a1315 commit fdb58fb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import java.util.Optional;
1717
import java.util.Set;
1818
import java.util.concurrent.TimeUnit;
19+
20+
import org.apache.commons.io.FileUtils;
21+
import org.apache.commons.lang.SystemUtils;
1922
import org.jetbrains.annotations.NotNull;
2023
import org.jetbrains.annotations.Nullable;
2124
import org.openqa.selenium.Capabilities;
@@ -205,7 +208,11 @@ protected void configure() {
205208
setCommand("/opt/bin/entry_point.sh");
206209

207210
if (getShmSize() == null) {
208-
this.getBinds().add(new Bind("/dev/shm", new Volume("/dev/shm"), AccessMode.rw));
211+
if (SystemUtils.IS_OS_WINDOWS) {
212+
withSharedMemorySize(512 * FileUtils.ONE_MB);
213+
} else {
214+
this.getBinds().add(new Bind("/dev/shm", new Volume("/dev/shm"), AccessMode.rw));
215+
}
209216
}
210217

211218
/*

modules/selenium/src/test/java/org/testcontainers/junit/BrowserWebDriverContainerTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.github.dockerjava.api.command.InspectContainerResponse;
44
import org.apache.commons.io.FileUtils;
5+
import org.apache.commons.lang.SystemUtils;
6+
import org.junit.Assume;
57
import org.junit.Test;
68
import org.openqa.selenium.chrome.ChromeOptions;
79
import org.openqa.selenium.firefox.FirefoxOptions;
@@ -50,6 +52,7 @@ public void provideDefaultNoProxyEnvironmentIfNotSet() {
5052

5153
@Test
5254
public void createContainerWithShmVolume() {
55+
Assume.assumeFalse("SHM isn't mounted on Windows", SystemUtils.IS_OS_WINDOWS);
5356
try (
5457
BrowserWebDriverContainer webDriverContainer = new BrowserWebDriverContainer()
5558
.withCapabilities(new FirefoxOptions())

0 commit comments

Comments
 (0)