selenium/node-docker
Selenium Grid Node with Dynamic capabilities
500K+
Grid 4 has the ability to start Docker containers on demand, this means that it starts a Docker container in the background for each new session request, the test gets executed there, and when the test completes, the container gets thrown away.
This execution mode can be used either in the Standalone or Node roles. The "dynamic"
execution mode needs to be told what Docker images to use when the containers get started.
Additionally, the Grid needs to know the URI of the Docker daemon. This configuration can
be placed in a local toml
file.
More details can be seen at the Dynamic Grid section in GitHub.
You can save this file locally and name it, for example, config.toml
.
[docker]
# Configs have a mapping between the Docker image to use and the capabilities that need to be matched to
# start a container with the given image.
configs = [
"selenium/standalone-firefox:latest", '{"browserName": "firefox"}',
"selenium/standalone-chrome:latest", '{"browserName": "chrome"}',
"selenium/standalone-edge:latest", '{"browserName": "MicrosoftEdge"}'
]
# URL for connecting to the docker daemon
# Most simple approach, leave it as http://127.0.0.1:2375, and mount /var/run/docker.sock.
# 127.0.0.1 is used because internally the container uses socat when /var/run/docker.sock is mounted
# If var/run/docker.sock is not mounted:
# Windows: make sure Docker Desktop exposes the daemon via tcp, and use http://host.docker.internal:2375.
# macOS: install socat and run the following command, socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock,
# then use http://host.docker.internal:2375.
# Linux: varies from machine to machine, please mount /var/run/docker.sock. If this does not work, please create an issue.
url = "http://127.0.0.1:2375"
# Docker image used for video recording
video-image = "selenium/video:ffmpeg-4.3.1-20230421"
# Uncomment the following section if you are running the node on a separate VM
# Fill out the placeholders with appropriate values
#[server]
#host = <ip-from-node-machine>
#port = <port-from-node-machine>
This can be expanded to a full Grid deployment, all components deployed individually. The overall idea is to have the Hub in one virtual machine, and each of the Nodes in separate and more powerful virtual machines.
macOS/Linux
$ docker network create grid
$ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:latest
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
-e SE_EVENT_BUS_PUBLISH_PORT=4442 \
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
-v ${PWD}/config.toml:/opt/bin/config.toml \
-v ${PWD}/assets:/opt/selenium/assets \
-v /var/run/docker.sock:/var/run/docker.sock \
selenium/node-docker:latest
Windows PowerShell
$ docker network create grid
$ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:latest
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub `
-e SE_EVENT_BUS_PUBLISH_PORT=4442 `
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
-v ${PWD}/config.toml:/opt/bin/config.toml `
-v ${PWD}/assets:/opt/selenium/assets `
-v /var/run/docker.sock:/var/run/docker.sock `
selenium/node-docker:latest
To have the assets saved on your host, please mount your host path to /opt/selenium/assets
.
Note: If you are mounting a volume in Linux, there is a known issue that can be solved through this workaround.
When you are done using the Grid, and the containers have exited, the network can be removed with the following command:
# Removes the grid network
$ docker network rm grid
Point your WebDriver tests to http://localhost:4444
That's it!
(Optional) To see what is happening inside the container, head to the Grid UI at http://localhost:4444/ui.
latest
as a tag, but we recommend to full tag to pin a specific browser and Grid version. Please see Tagging Conventions for details.The tag structure is as follows:
selenium/standalone-docker-<Major>.<Minor>.<Patch>-<YYYYMMDD>
Selenium Server 4.9.0
Release date 20230426
e126989f151e selenium/node-docker 4
e126989f151e selenium/node-docker 4.9
e126989f151e selenium/node-docker 4.9.0
e126989f151e selenium/node-docker 4.9.0-20230426
With that, you can use any of the different tags to get the most recent release in a simplified way.
The Docker-Selenium project in GitHub has an extensive README that will help you find the correct way to get this images up and running for your use case.
The project is made possible by volunteer contributors who have put in thousands of hours of their own time, and made the source code freely available under the Apache License 2.0.
docker pull selenium/node-docker