testcontainers-java
testcontainers-java copied to clipboard
[Bug]: Cannot "augment" selenium driver
Module
Selenium
Testcontainers version
1.19.8
Using the latest Testcontainers version?
Yes
Host OS
Windows
Host Arch
x86
Docker version
λ podman version
Client: Podman Engine
Version: 5.1.1
API Version: 5.1.1
Go Version: go1.22.3
Git Commit: bda6eb03dcbcf12a5b7ae004c1240e38dd056d24
Built: Tue Jun 4 23:40:05 2024
OS/Arch: windows/amd64
Server: Podman Engine
Version: 5.1.1
API Version: 5.1.1
Go Version: go1.22.3
Built: Tue Jun 4 02:00:00 2024
OS/Arch: linux/amd64
What happened?
Hello,
I'm trying to use the Seleium module to execute browser tests inside a quarkus project. I can successfully create the browser, but when I attempt to augment it through the following code
new Augmenter().augment(driver)
this fails because the reported CDP URL (chrome devtools protocol) is the URL inside the docker network Augmenting the driver allows to use new features of Selenium like BiDi.
Selenium documentation (https://github.com/SeleniumHQ/docker-selenium?tab=readme-ov-file#grid-url-and-session-timeout) states that the environment variable SE_NODE_GRID_URL must be used in such case. But this is not possible with testcontainer because the URL I need to give to SE_NODE_GRID_URL environment variable must contain the random port that testcontainers provides on start up of container.
I think it's similar to the issue https://github.com/testcontainers/testcontainers-java/issues/256 and so, it may be useful to pass this environment variable automatically before selenium container starts
Thanks
Relevant log output
No response
Additional Information
No response
Thanks for reporting the issue. In the past, I was able to do something like is described here.
Hello @eddumelendez
Thank you for your suggestion After raising the issue, I managed to augment the selenium driver providing a random port using port binding like
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(randomPortSelenium), new ExposedPort(4444) , Ports.Binding.bindPort(randomPortVnc), new ExposedPort(5900))))
)
But this only work if VNC is disabled Enabling VNC is not possible as using such port bindings seems to modify network aliases that the selenium container exposes
Hello,
I've tested with your suggestion, but same problem with VNC, container does not start (I suppose it's due to the fact that we are on a network that the VNC container does not know)
Ran into this too. Tried using newer builder pattern,
WebDriver driver = RemoteWebDriver.builder()
.address(webDriverContainer.getSeleniumAddress())
.oneOf(browserOptions)
.build();
later read that this auto-applies the augmentation
changed it to
WebDriver driver = new RemoteWebDriver(webDriverContainer.getSeleniumAddress(), browserOptions);
and its working
confusing, because the only error is HTTP connect timed out on SeleniumCdpConnection
I solved my problem using
BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()
.withCapabilities(new ChromeOptions())
.withEnv("SE_NODE_GRID_URL", "http://localhost:4444")
.withEnv("SE_OPTS", " --docker-video-image false")
.withEnv("SE_RECORD_VIDEO", "true")
.withEnv("SE_VIDEO_RECORD_STANDALONE", "true")
.withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.SKIP, File.createTempFile("video", ".mp4"));
and before augmenting driver, I change it's se:cdp capability to point to the port exposed by testcontainers and not 4444
try {
String cdp = ((HasCapabilities)driver).getCapabilities().getCapability("se:cdp").toString();
int cdpPort = new URI(cdp).getPort();
int hubPort = new URL(gridHubUrl).getPort();
cdp = cdp.replace(":" + cdpPort + "/", ":" + hubPort + "/");
((MutableCapabilities)((HasCapabilities)driver).getCapabilities()).setCapability("se:cdp", cdp);
} catch (MalformedURLException | URISyntaxException e) {
return;
}