Giter VIP home page Giter VIP logo

seleniumhq / docker-selenium Goto Github PK

View Code? Open in Web Editor NEW
7.4K 253.0 2.5K 3.36 MB

Provides a simple way to run Selenium Grid with Chrome, Firefox, and Edge using Docker, making it easier to perform browser automation

Home Page: http://www.selenium.dev/docker-selenium/

License: Other

Shell 46.87% Makefile 12.51% Python 14.42% Dockerfile 11.74% Smarty 14.45%
selenium selenium-grid selenium-node selenium-server webdriver docker docker-selenium kubernetes-selenium kubernetes

docker-selenium's Introduction

Build & test Test Docker Selenium Test Helm Charts Deploys Release Charts Nightly Update Dev/Beta Browser Images

Docker images for the Selenium Grid Server

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.

These Docker images come with a handful of tags to simplify its usage, have a look at them in one of our releases.

To get notifications of new releases, add yourself as a "Releases only" watcher.

These images are published to the Docker Hub registry at Selenium Docker Hub.

Community

Do you need help to use these Docker images? Talk to us at https://www.selenium.dev/support/

Contents

Quick start

  1. Start a Docker container with Firefox
docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-firefox:4.20.0-20240425
  1. Point your WebDriver tests to http://localhost:4444

  2. That's it!

  3. (Optional) To see what is happening inside the container, head to http://localhost:7900/?autoconnect=1&resize=scale&password=secret.

For more details about visualising the container activity, check the Debugging section.

☝️ When executing docker run for an image that contains a browser please use the flag --shm-size=2g to use the host's shared memory.

☝️ Always use a Docker image with a full tag to pin a specific browser and Grid version. See Tagging Conventions for details.

Try them out in a ready-to-use GitPod environment!

Open in Gitpod


Experimental Mult-Arch aarch64/armhf/amd64 Images

For experimental docker container images, which run on platforms such as the Mac M1 or Raspberry Pi, see the community-driven repository hosted at seleniumhq-community/docker-seleniarm. These images are built for three separate architectures: linux/arm64 (aarch64), linux/arm/v7 (armhf), and linux/amd64.

Furthermore, these experimental container images are published on Seleniarm Docker Hub registry.

See issue #1076 for more information on these images.

If you're working on an Intel or AMD64 architecture, we recommend using the container images in this repository (SeleniumHQ/docker-selenium) instead of the experimental ones.


Nightly Images

Nightly images are built on top of the Nightly build on the upstream project Selenium with the latest changes on main branch in this repository. The image tag is nightly. This is not recommended to use images in production. It is only for testing purpose.

$ docker run -d -p 4442-4444:4442-4444 --name selenium-hub selenium/hub:nightly

Dev and Beta Channel Browser Images

To run tests or otherwise work with pre-release browsers, Google, Mozilla, and Microsoft maintain a Dev and Beta release channel for those who need to see what's soon to be released to the general population.

Dev and Beta Standalone Mode

Here are the instructions to run them in Standalone mode:

Chrome Beta:

$ docker run --rm -it -p 4444:4444 -p 7900:7900 --shm-size 2g selenium/standalone-chrome:beta

Chrome Dev:

$ docker run --rm -it -p 4444:4444 -p 7900:7900 --shm-size 2g selenium/standalone-chrome:dev

Firefox Beta:

$ docker run --rm -it -p 4444:4444 -p 7900:7900 --shm-size 2g selenium/standalone-firefox:beta

Firefox Dev:

$ docker run --rm -it -p 4444:4444 -p 7900:7900 --shm-size 2g selenium/standalone-firefox:dev

Edge Beta:

$ docker run --rm -it -p 4444:4444 -p 7900:7900 --shm-size 2g selenium/standalone-edge:beta

Edge Dev:

$ docker run --rm -it -p 4444:4444 -p 7900:7900 --shm-size 2g selenium/standalone-edge:dev

Dev and Beta on the Grid

docker-compose-v3-beta-channel.yml:

# To execute this docker compose yml file use `docker compose -f docker-compose-v3-beta-channel.yml up`
# Add the `-d` flag at the end for detached execution
# To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-v3-beta-channel.yml down`
version: "3"
services:
  chrome:
    image: selenium/node-chrome:beta
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  edge:
    image: selenium/node-edge:beta
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  firefox:
    image: selenium/node-firefox:beta
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-hub:
    image: selenium/hub:latest
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

docker-compose-v3-dev-channel.yml:

# To execute this docker compose yml file use `docker compose -f docker-compose-v3-dev-channel.yml up`
# Add the `-d` flag at the end for detached execution
# To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-v3-dev-channel.yml down`
version: "3"
services:
  chrome:
    image: selenium/node-chrome:dev
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  edge:
    image: selenium/node-edge:dev
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  firefox:
    image: selenium/node-firefox:dev
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-hub:
    image: selenium/hub:latest
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

For more information on the Dev and Beta channel container images, see the blog post on Dev and Beta Channel Browsers via Docker Selenium.

Execution modes

Standalone

Firefox Firefox

docker run -d -p 4444:4444 --shm-size="2g" selenium/standalone-firefox:4.20.0-20240425

Chrome Chrome

docker run -d -p 4444:4444 --shm-size="2g" selenium/standalone-chrome:4.20.0-20240425

Edge Edge

docker run -d -p 4444:4444 --shm-size="2g" selenium/standalone-edge:4.20.0-20240425

Note: Only one Standalone container can run on port 4444 at the same time.


Hub and Nodes

There are different ways to run the images and create a Grid with a Hub and Nodes, check the following options.

Docker networking

The Hub and Nodes will be created in the same network and they will recognize each other by their container name. A Docker network needs to be created as a first step.

macOS/Linux
$ docker network create grid
$ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-chrome:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-edge:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-firefox:4.20.0-20240425
Windows PowerShell
$ docker network create grid
$ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub `
    --shm-size="2g" `
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 `
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
    selenium/node-chrome:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub `
    --shm-size="2g" `
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 `
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
    selenium/node-edge:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub `
    --shm-size="2g" `
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 `
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
    selenium/node-firefox:4.20.0-20240425

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

Using different machines/VMs

The Hub and Nodes will be created on different machines/VMs, they need to know each other's IPs to communicate properly. If more than one node will be running on the same Machine/VM, they must be configured to expose different ports.

Hub - Machine/VM 1
$ docker run -d -p 4442-4444:4442-4444 --name selenium-hub selenium/hub:4.20.0-20240425
Node Chrome - Machine/VM 2
macOS/Linux
$ docker run -d -p 5555:5555 \
    --shm-size="2g" \
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    -e SE_NODE_HOST=<ip-from-machine-2> \
    selenium/node-chrome:4.20.0-20240425
Windows PowerShell
$ docker run -d -p 5555:5555 `
    --shm-size="2g" `
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> `
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 `
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
    -e SE_NODE_HOST=<ip-from-machine-2> `
    selenium/node-chrome:4.20.0-20240425
Node Edge - Machine/VM 3
macOS/Linux
$ docker run -d -p 5555:5555 \
    --shm-size="2g" \
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    -e SE_NODE_HOST=<ip-from-machine-3> \
    selenium/node-edge:4.20.0-20240425
Windows PowerShell
$ docker run -d -p 5555:5555 `
    --shm-size="2g" `
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> `
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 `
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
    -e SE_NODE_HOST=<ip-from-machine-3> `
    selenium/node-edge:4.20.0-20240425
Node Firefox - Machine/VM 4
macOS/Linux
$ docker run -d -p 5555:5555 \
    --shm-size="2g" \
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    -e SE_NODE_HOST=<ip-from-machine-4> \
    selenium/node-firefox:4.20.0-20240425
Windows PowerShell
$ docker run -d -p 5555:5555 `
    --shm-size="2g" `
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> `
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 `
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
    -e SE_NODE_HOST=<ip-from-machine-4> `
    selenium/node-firefox:4.20.0-20240425
Node Chrome - Machine/VM 4
macOS/Linux
$ docker run -d -p 5556:5556 \
    --shm-size="2g" \
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    -e SE_NODE_HOST=<ip-from-machine-4> \
    -e SE_NODE_PORT=5556 \
    selenium/node-chrome:4.20.0-20240425
Windows PowerShell
$ docker run -d -p 5556:5556 `
    --shm-size="2g" `
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> `
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 `
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 `
    -e SE_NODE_HOST=<ip-from-machine-4> `
    -e SE_NODE_PORT=5556 `
    selenium/node-chrome:4.20.0-20240425

Docker Compose

Docker Compose is the simplest way to start a Grid. Use the linked resources below, save them locally and check the execution instructions on top of each file.

Version 2

docker-compose-v2.yml

Version 3

docker-compose-v3.yml

To stop the Grid and cleanup the created containers, run docker compose down.

Version 3 with Swarm support

docker-compose-v3-swarm.yml


Fully distributed mode - Router, Queue, Distributor, EventBus, SessionMap and Nodes

It is possible to start a Selenium Grid with all its components apart. For simplicity, only an example with docker compose will be provided. Save the file locally, and check the execution instructions on top of it.

docker-compose-v3-full-grid.yml

Distributor configuration

Environment variable Option Type Default value Description
SE_REJECT_UNSUPPORTED_CAPS --reject-unsupported-caps boolean false Allow the Distributor to reject a request immediately if the Grid does not support the requested capability.
SE_HEALTHCHECK_INTERVAL --healthcheck-interval int 120 This ensures the server can ping all the Nodes successfully after an interval.

Video recording

Tests execution can be recorded by using the selenium/video:ffmpeg-7.0-20240425 Docker image. One container is needed per each container where a browser is running. This means if you are running 5 Nodes/Standalone containers, you will need 5 video containers, the mapping is 1-1.

Currently, the only way to do this mapping is manually (either starting the containers manually or through docker compose). We are iterating on this process and probably this setup will be more simple in the future.

The video Docker image we provide is based on the ffmpeg Ubuntu image provided by the jrottenberg/ffmpeg project, thank you for providing this image and simplifying our work 🎉

Notes:

  • If you have questions or feedback, please use the community contact points shown here.
  • Please report any bugs through GitHub issues, and provide all the information requested on the template.
  • Video recording for headless browsers is not supported.
  • Video recording tends to use considerable amounts of CPU. Normally you should estimate 1CPU per video container, and 1 CPU per browser container.
  • Videos are stored in the /videos directory inside the video container. Map a local directory to get the videos.
  • If you are running more than one video container, be sure to overwrite the video file name through the FILE_NAME environment variable to avoid unexpected results.

This example shows how to start the containers manually:

$ docker network create grid
$ docker run -d -p 4444:4444 -p 6900:5900 --net grid --name selenium --shm-size="2g" selenium/standalone-chrome:4.20.0-20240425
$ docker run -d --net grid --name video -v /tmp/videos:/videos selenium/video:ffmpeg-7.0-20240425
# Run your tests
$ docker stop video && docker rm video
$ docker stop selenium && docker rm selenium

After the containers are stopped and removed, you should see a video file on your machine's /tmp/videos directory.

Here is an example using a Hub and a few Nodes:

docker-compose-v3-video.yml

Video recording and uploading

RCLONE is installed in the video recorder image. You can use it to upload the videos to a cloud storage service. Besides the video recording mentioned above, you can enable the upload functionality by setting the following environment variables:

version: "3"
services:
  chrome_video:
    image: selenium/video:nightly
    depends_on:
      - chrome
    environment:
      - DISPLAY_CONTAINER_NAME=chrome
      - SE_VIDEO_FILE_NAME=auto
      - SE_VIDEO_UPLOAD_ENABLED=true
      - SE_VIDEO_INTERNAL_UPLOAD=true
      - SE_UPLOAD_DESTINATION_PREFIX=s3://mybucket/path
      - RCLONE_CONFIG_S3_TYPE=s3
      - RCLONE_CONFIG_S3_PROVIDER=GCS
      - RCLONE_CONFIG_S3_ENV_AUTH=true
      - RCLONE_CONFIG_S3_REGION=asia-southeast1
      - RCLONE_CONFIG_S3_LOCATION_CONSTRAINT=asia-southeast1
      - RCLONE_CONFIG_S3_ACL=private
      - RCLONE_CONFIG_S3_ACCESS_KEY_ID=xxx
      - RCLONE_CONFIG_S3_SECRET_ACCESS_KEY=xxx
      - RCLONE_CONFIG_S3_ENDPOINT=https://storage.googleapis.com
      - RCLONE_CONFIG_S3_NO_CHECK_BUCKET=true

SE_VIDEO_FILE_NAME=auto will use the session id as the video file name. This ensures that the video file name is unique to upload.

SE_VIDEO_UPLOAD_ENABLED=true will enable the video upload feature. In the background, it will create a pipefile with file and destination for uploader to consume and proceed.

SE_VIDEO_INTERNAL_UPLOAD=true will use RCLONE installed in the container for upload. If you want to use another container for upload, set it to false.

For environment variables with prefix RCLONE_ is used to pass remote configuration to RCLONE. You can find more information about RCLONE configuration here.

docker-compose-v3-video-upload.yml

Note that upload function is not supported for Dynamic Grid. If you want it, please create a feature request.


Dynamic Grid

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.

Configuration example

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:4.20.0-20240425", '{"browserName": "firefox"}',
    "selenium/standalone-chrome:4.20.0-20240425", '{"browserName": "chrome"}',
    "selenium/standalone-edge:4.20.0-20240425", '{"browserName": "MicrosoftEdge"}'
]

host-config-keys = ["Dns", "DnsOptions", "DnsSearch", "ExtraHosts", "Binds"]

# 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-7.0-20240425"

# 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>

With the optional config key host-config-keys under section [docker] in a config.toml file (or CLI option --docker-host-config-keys). Users can specify a list of docker host configuration keys that should be passed to browser containers.

Valid key names for Docker host config can be found in the Docker API documentation or via the command docker inspect the node-docker container.

Execution with Hub & Node roles

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:4.20.0-20240425
$ 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:4.20.0-20240425

Windows PowerShell

$ docker network create grid
$ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4.20.0-20240425
$ 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:4.20.0-20240425

To have the assets saved on your host, please mount your host path to /opt/selenium/assets.

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

Execution with Standalone roles

macOS/Linux

docker run --rm --name selenium-docker -p 4444:4444 \
    -v ${PWD}/config.toml:/opt/bin/config.toml \
    -v ${PWD}/assets:/opt/selenium/assets \
    -v /var/run/docker.sock:/var/run/docker.sock \
    selenium/standalone-docker:4.20.0-20240425

Windows PowerShell

docker run --rm --name selenium-docker -p 4444:4444 `
    -v ${PWD}/config.toml:/opt/bin/config.toml `
    -v ${PWD}/assets:/opt/selenium/assets `
    -v /var/run/docker.sock:/var/run/docker.sock `
    selenium/standalone-docker:4.20.0-20240425

Using Dynamic Grid in different machines/VMs

Hub - Machine/VM 1

$ docker run -d -p 4442-4444:4442-4444 --name selenium-hub selenium/hub:4.20.0-20240425

Node Chrome - Machine/VM 2

macOS/Linux

$ docker run -d -p 5555:5555 \
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
    -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:4.20.0-20240425

Windows PowerShell

$ docker run -d -p 5555:5555 `
    -e SE_EVENT_BUS_HOST=<ip-from-machine-1> `
    -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:4.20.0-20240425

Complete the [server] section in the config.toml file.

[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:4.20.0-20240425", "{\"browserName\": \"firefox\"}",
    "selenium/standalone-chrome:4.20.0-20240425", "{\"browserName\": \"chrome\"}",
    "selenium/standalone-edge:4.20.0-20240425", "{\"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 interally 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-7.0-20240425"

# 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>

To have the assets saved on your host, please mount your host path to /opt/selenium/assets.

Execution with Docker Compose

Here is an example using a Hub and a Node:

docker-compose-v3-dynamic-grid.yml

Configuring the child containers

Containers can be further configured through environment variables, such as SE_NODE_SESSION_TIMEOUT and SE_OPTS. When a child container is created, all environment variables prefixed with SE_ will be forwared and set in the container. You can set the desired environment variables in the standalone-docker or node-docker containers. The following example sets the session timeout to 700 seconds for all sessions:

macOS/Linux

docker run --rm --name selenium-docker -p 4444:4444 \
    -e SE_NODE_SESSION_TIMEOUT=700 \
    -v ${PWD}/config.toml:/opt/bin/config.toml \
    -v ${PWD}/assets:/opt/selenium/assets \
    -v /var/run/docker.sock:/var/run/docker.sock \
    selenium/standalone-docker:4.20.0-20240425

Windows PowerShell

docker run --rm --name selenium-docker -p 4444:4444 `
    -e SE_NODE_SESSION_TIMEOUT=700 `
    -v ${PWD}/config.toml:/opt/bin/config.toml `
    -v ${PWD}/assets:/opt/selenium/assets `
    -v /var/run/docker.sock:/var/run/docker.sock `
    selenium/standalone-docker:4.20.0-20240425

Video recording, screen resolution, and time zones in a Dynamic Grid

To record your WebDriver session, you need to add a se:recordVideo field set to true. You can also set a time zone and a screen resolution, for example:

{
  "browserName": "firefox",
  "platformName": "linux",
  "se:recordVideo": "true",
  "se:timeZone": "US/Pacific",
  "se:screenResolution": "1920x1080"  
}

After running a test, check the path you mounted to the Docker container, (${PWD}/assets), and you should see videos and session information.


Deploying to Kubernetes

We offer a Helm chart to deploy these Docker images to Kubernetes. Read more details at the Helm readme.


Configuring the containers

SE_OPTS Selenium Configuration Options

You can pass SE_OPTS variable with additional command line parameters for starting a hub or a node.

$ docker run -d -p 4444:4444 -e SE_OPTS="--log-level FINE" --name selenium-hub selenium/hub:4.20.0-20240425

SE_JAVA_OPTS Java Environment Options

You can pass SE_JAVA_OPTS environment variable to the Java process.

$ docker run -d -p 4444:4444 -e SE_JAVA_OPTS=-Xmx512m --name selenium-hub selenium/hub:4.20.0-20240425

Node configuration options

The Nodes register themselves through the Event Bus. When the Grid is started in its typical Hub/Node setup, the Hub will be the one acting as the Event Bus, and when the Grid is started with all its five elements apart, the Event Bus will be running on its own.

In both cases, it is necessary to tell the Node where the Event Bus is, so it can register itself. That is the purpose of the SE_EVENT_BUS_HOST, SE_EVENT_BUS_PUBLISH_PORT and SE_EVENT_BUS_SUBSCRIBE_PORT environment variables.

In some cases, for example, if you want to tag a node, it might be necessary to supply a custom stereotype to the node config. The environment variable SE_NODE_STEREOTYPE sets the stereotype entry in the node's config.toml. An example config.toml file can be found here: Setting custom capabilities for matching specific Nodes.

Here is an example with the default values of these environment variables:

$ docker run -d \
  -e SE_EVENT_BUS_HOST=<event_bus_ip|event_bus_name> \
  -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
  -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -e SE_NODE_STEREOTYPE="{\"browserName\":\"${SE_NODE_BROWSER_NAME}\",\"browserVersion\":\"${SE_NODE_BROWSER_VERSION}\",\"platformName\": \"Linux\"}" \
  --shm-size="2g" selenium/node-chrome:4.20.0-20240425

Setting Sub Path

By default, Selenium is reachable at http://127.0.0.1:4444/. Selenium can be configured to use a custom subpath by specifying the SE_SUB_PATH environmental variable. In the example below Selenium is reachable at http://127.0.0.1:4444/selenium-grid/

$ docker run -d -p 4444:4444 -e SE_SUB_PATH=/selenium-grid/ --name selenium-hub selenium/hub:4.9.0-20230421

Setting Screen Resolution

By default, nodes start with a screen resolution of 1360 x 1020 with a color depth of 24 bits and a dpi of 96. These settings can be adjusted by specifying SE_SCREEN_WIDTH, SE_SCREEN_HEIGHT, SE_SCREEN_DEPTH, and/or SE_SCREEN_DPI environmental variables when starting the container.

docker run -d -e SE_SCREEN_WIDTH=1366 -e SE_SCREEN_HEIGHT=768 -e SE_SCREEN_DEPTH=24 -e SE_SCREEN_DPI=74 selenium/standalone-firefox:4.20.0-20240425

Grid Url and Session Timeout

In some use cases, you might need to set the Grid URL to the Node, for example, if you'd like to access the BiDi/CDP endpoint. This is also needed when you want to use the new RemoteWebDriver.builder() or Augmenter() present in Selenium 4 (since they setup the BiDi/CDP connection implicitly). You can do that through the SE_NODE_GRID_URL environment variable, eg -e SE_NODE_GRID_URL=http://<hostMachine>:4444. Setting this env var is needed if you want to see the live view while sessions are executing.

Grid has a default session timeout of 300 seconds, where the session can be in a stale state until it is killed. You can use SE_NODE_SESSION_TIMEOUT to overwrite that value in seconds.

Session request timeout

A new session request is placed in the Session Queue before it is processed, and the request sits in the queue until a matching slot is found across the registered Nodes. However, the new session request might timeout if no slot was found. By default, a request will stay in the queue for up to 300 seconds before it a timeout is reached. In addition, an attempt to process the request is done every 5 seconds (by default).

It is possible to override those values through environment variables in the Hub and the SessionQueue (SE_SESSION_REQUEST_TIMEOUT and SE_SESSION_RETRY_INTERVAL). For example, a timeout of 500 seconds would be SE_SESSION_REQUEST_TIMEOUT=500 and a retry interval of 2 seconds would be SE_SESSION_RETRY_INTERVAL=2.

Increasing session concurrency per container

By default, only one session is configured to run per container through the SE_NODE_MAX_SESSIONS environment variable. It is possible to increase that number up to the maximum available processors, this is because more stability is achieved when one container/browser has 1 CPU to run.

However, if you have measured performance and based on that, you think more sessions can be executed in each container, you can override the maximum limit by setting both SE_NODE_MAX_SESSIONS to a desired number and SE_NODE_OVERRIDE_MAX_SESSIONS to true. Nevertheless, running more browser sessions than the available processors is not recommended since you will be overloading the resources.

Overriding this setting has an undesired side effect when video recording is enabled since more than one browser session might be captured in the same video.

Running in Headless mode

Firefox, Chrome, When using headless mode, there's no need for the Xvfb server to be started.

To avoid starting the server you can set the SE_START_XVFB environment variable to false (or any other value than true), for example:

$ 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 -e SE_START_XVFB=false --shm-size="2g" selenium/node-chrome:4.20.0-20240425

For more information, see this GitHub issue.

Stopping the Node/Standalone after N sessions have been executed

In some environments, like Docker Swarm or Kubernetes, it is useful to shut down the Node or Standalone container after N tests have been executed. For example, this can be used in Kubernetes to terminate the pod and then scale a new one after N sessions. Set the environment variable SE_DRAIN_AFTER_SESSION_COUNT to a value higher than zero to enable this behaviour.

$ docker run -e SE_DRAIN_AFTER_SESSION_COUNT=5 --shm-size="2g" selenium/standalone-firefox:4.20.0-20240425

With the previous command, the Standalone container will shut down after 5 sessions have been executed.

Automatic browser leftovers cleanup

In long-running containers, it can happen that browsers leave some leftovers. These can be stuck browser processes of jobs that have already finished but failed to fully stop the browser, or temporary files written to the /tmp file system (notably on Chrome-based browsers). To avoid these filling up resources like process IDs and file system usage in the container, there is an automatic cleanup script running every hour in the node containers. This will clean up old processes and old temporary files. By default, this is disabled. When enabled, this will clean up browsers running for longer than 2 hours, and files older than 1 day. These can be enabled and tweaked with the following environment variables:

  • SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP: default value false, set to true to enable the cleanup.
  • SE_BROWSER_LEFTOVERS_INTERVAL_SECS: default value 3600 (1 hour), cleanup interval in seconds.
  • SE_BROWSER_LEFTOVERS_PROCESSES_SECS: default value 7200 (2 hours), browsers running for longer than this time will be killed.
  • SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS: default value 1 (1 day), files generated by Chrome-based browsers in /tmp will be removed after these number of days (ignored when using Firefox).

If you use Selenium for long-running sessions and expect browsers to be running for longer than 2 hours, either do not set SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP to true (leave the default value of false), or tweak SE_BROWSER_LEFTOVERS_PROCESSES_SECS to set a value higher than your expected long-running browser processes.

$ docker run -e SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP=true --shm-size="2g" selenium/node-chrome:4.20.0-20240425

With the previous command, the cleanup will be enabled with the default timings.

$ docker run -e SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP=true \
-e SE_BROWSER_LEFTOVERS_INTERVAL_SECS=7200 \
-e SE_BROWSER_LEFTOVERS_PROCESSES_SECS=3600 \
-e SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS=2 \
--shm-size="2g" selenium/node-chrome:4.20.0-20240425

With the previous command, the cleanup will be enabled, but will run every 2 hours (instead of 1), will kill browsers running longer than 1 hour (instead of 2 hours), and will remove temp files older than 2 days (instead of 1).


Building the images

Clone the repo and from the project directory root you can build everything by running:

$ VERSION=local make build

If you need to configure environment variables in order to build the image (http proxy for instance), simply set an environment variable BUILD_ARGS that contains the additional variables to pass to the docker context (this will only work with docker >= 1.9)

$ BUILD_ARGS="--build-arg http_proxy=http://acme:3128 --build-arg https_proxy=http://acme:3128" make build

Note: Omitting VERSION=local will build the images with the released version but replacing the date for the current one.

If you want to build the image with the host UID/GID, simply set an environment variable BUILD_ARGS

$ BUILD_ARGS="--build-arg UID=$(id -u) --build-arg GID=$(id -g)" make build

If you want to build the image with different default user/password, simply set an environment variable BUILD_ARGS

$ BUILD_ARGS="--build-arg SEL_USER=yourseluser --build-arg SEL_PASSWD=welcome" make build

Build the images with specific versions

Based on the latest Dockerfile (by cloning the repo and from the project directory root), you can build the images with a specific combination of Selenium Grid, and browser versions.

For example, you would like to build node-chrome and standalone-chrome images with the Grid based version 4.17.0, Chrome browser versions 119, 120, 123 respectively.

$ ./tests/build-backward-compatible/bootstrap.sh 4.17.0 119,120,123 chrome

In generic, the script takes the following arguments:

  • $1 (mandatory): Selenium Grid version. Details are fetching from matrix file
  • $2 (mandatory): Browser major version, multiple values separated by comma. Details are fetching from matrix file
  • $3 (optional): browser name. If not provided, it will iterate over all the browsers (chrome, edge, firefox)
  • $4 (optional): Push image to registry. By default, it is false. If you want to push the image to the registry, set it to true (required Docker login to your namespace done before running the script).

To set your namespace for the images, you can set the environment variable NAME before running the script. For example:

$ export NAME=artifactory.yourcompany.com/selenium
$ ./tests/build-backward-compatible/bootstrap.sh 4.17.0 119,120,123 chrome

After running the script, you will see list images with a full tag to pin specific Grid and browser version following Tagging Conventions


Upgrade browser version in the images

Selenium server, browser and driver are pre-installed in the image. In case you would like to remain on the same Selenium version and just upgrade the browser and its driver to the latest. You can follow below steps

Clone the repo and from the project directory root you can upgrade by running:

$ VERSION=$EXPECTED_SELENIUM_VERSION make chrome_upgrade_version

For example: VERSION=4.16.1 make chrome_upgrade_version

The new image has tag $VERSION_YYYYMMDD where YYYYMMDD is the current date.

$ VERSION=$SELENIUM_VERSION make firefox_upgrade_version
$ VERSION=$SELENIUM_VERSION make edge_upgrade_version

You can refer to detail commands in the Makefile file.


Waiting for the Grid to be ready

It is a good practice to check first if the Grid is up and ready to receive requests, this can be done by checking the /wd/hub/status endpoint.

A Grid that is ready, composed of a hub and two nodes, could look like this:

{
  "value": {
    "ready": true,
    "message": "Selenium Grid ready.",
    "nodes": [
      {
        "id": "6c0a2c59-7e99-469d-bbfc-313dc638797c",
        "uri": "http:\u002f\u002f172.19.0.3:5555",
        "maxSessions": 4,
        "stereotypes": [
          {
            "capabilities": {
              "browserName": "firefox"
            },
            "count": 4
          }
        ],
        "sessions": [
        ]
      },
      {
        "id": "26af3363-a0d8-4bd6-a854-2c7497ed64a4",
        "uri": "http:\u002f\u002f172.19.0.4:5555",
        "maxSessions": 4,
        "stereotypes": [
          {
            "capabilities": {
              "browserName": "chrome"
            },
            "count": 4
          }
        ],
        "sessions": [
        ]
      }
    ]
  }
}

The "ready": true value indicates that the Grid is ready to receive requests. This status can be polled through a script before running any test, or it can be added as a HEALTHCHECK when the docker container is started.

Adding a HEALTHCHECK to the Grid

The script check-grid.sh, which is included in the images, can be used to poll the Grid status.

This example checks the status of the Grid every 15 seconds, it has a timeout of 30 seconds when the check is done, and it retries up to 5 times until the container is marked as unhealthy. Please use adjusted values to fit your needs, (if needed) replace the --host and --port parameters for the ones used in your environment.

$ docker network create grid
$ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub \
  --health-cmd='/opt/bin/check-grid.sh --host 0.0.0.0 --port 4444' \
  --health-interval=15s --health-timeout=30s --health-retries=5 \
  selenium/hub:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-chrome:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-edge:4.20.0-20240425
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-firefox:4.20.0-20240425

Note: The \ line delimiter won't work on Windows-based terminals, try either ^ or a backtick.

The container health status can be checked by doing docker ps and verifying the (healthy)|(unhealthy) status or by inspecting it in the following way:

$ docker inspect --format='{{json .State.Health.Status}}' selenium-hub
"healthy"

Using a bash script to wait for the Grid

A common problem known in docker is that a running container does not always mean that the application inside it is ready. A simple way to tackle this is by using a "wait-for-it" script, more information can be seen here.

The following script is an example of how this can be done using bash, but the same principle applies if you want to do this with the programming language used to write the tests. In the example below, the script will poll the status endpoint every second. If the grid does not become ready within 30 seconds, the script will exit with an error code.

#!/bin/bash
# wait-for-grid.sh

set -e
url="http://localhost:4444/wd/hub/status"
wait_interval_in_seconds=1
max_wait_time_in_seconds=30
end_time=$((SECONDS + max_wait_time_in_seconds))
time_left=$max_wait_time_in_seconds

while [ $SECONDS -lt $end_time ]; do
    response=$(curl -sL "$url" | jq -r '.value.ready')
    if [ -n "$response"  ]  && [ "$response" ]; then
        echo "Selenium Grid is up - executing tests"
        break
    else
        echo "Waiting for the Grid. Sleeping for $wait_interval_in_seconds second(s). $time_left seconds left until timeout."
        sleep $wait_interval_in_seconds
        time_left=$((time_left - wait_interval_in_seconds))
    fi
done

if [ $SECONDS -ge $end_time ]; then
    echo "Timeout: The Grid was not started within $max_wait_time_in_seconds seconds."
    exit 1
fi

Will require jq installed via apt-get, else the script will keep printing Waiting without completing the execution.

Note: If needed, replace localhost and 4444 for the correct values in your environment. Also, this script is polling indefinitely, you might want to tweak it and establish a timeout.

Let's say that the normal command to execute your tests is mvn clean test. Here is a way to use the above script and execute your tests:

$ ./wait-for-grid.sh mvn clean test

Like this, the script will poll until the Grid is ready, and then your tests will start.


Install certificates for Chromium-based browsers

By default, the based image is installed libnss3-tools and initializes /home/seluser/.pki/nssdb, so you are able to add your certs with rootless. If you need to install custom certificates, CA, intermediate CA, or client certificates (for example, enterprise internal CA) you can create your own docker image from selenium node image. The Chromium-based browser uses nssdb as a certificate store. You can then install all required internal certificates in your Dockerfile like this:

  • Create a script for installing the certificates. For example, cert-script.sh
  • Create a Dockerfile that uses the selenium node image as a base and copies the script to the container, and executes it. For example, Dockerfile
  • If you have to create a set of different certificates and node images. You can create a bootstrap script to do that in one-shot. For example, bootstrap.sh

The above example can be tested with the following command:

make test_custom_ca_cert
# ./tests/customCACert/bootstrap.sh

You can find more information here

This way the certificates will be installed and the node will start automatically as before.


Alternative method: Add certificates to existing Selenium based images for browsers

As an alternative, you can add your certificate files to existing Selenium images. This practical example assumes you have a known image to use as a build image and have a way to publish new images to your local docker registry.

This example uses a RedHat-based distro as a build image (Rocky Linux) but it can be any Linux image of your choice. Please note that build instruction will vary between distributions. You can check the instructions for Ubuntu in the previous example.

The example also assumes your internal CA is already in /etc/pki/ca-trust/source/anchors/YOUR_CA.pem, the default location for Rocky Linux. Alternatively, you can also provide these files from your host and copy them into the build image.

For Chrome and Edge browsers, the recipe is the same, just adapt the image name (node-chrome or node-edge):

# Get a standard image for creating nssdb file
FROM rockylinux:8.6 as build
RUN yum install -y nss-tools
RUN mkdir -p -m755 /seluser/.pki/nssdb \
    && certutil -d sql:/seluser/.pki/nssdb -N --empty-password \
    && certutil -d sql:/seluser/.pki/nssdb -A -t "C,," -n YOUR_CA -i /etc/pki/ca-trust/source/anchors/YOUR_CA.pem \
    && chown -R 1200:1201 /seluser

# Start from Selenium image and add relevant files from build image
FROM selenium/node-chrome:4.20.0-20240425
USER root
COPY --from=build /seluser/ /home/seluser/
USER seluser

Example for Firefox:

# Get a standard image for working on
FROM rockylinux:8.6 as build
RUN mkdir -p "/distribution" "/certs" && \
    cp /etc/pki/ca-trust/source/anchors/YOUR_CA*.pem /certs/ && \
    echo '{ "policies": { "Certificates": { "Install": ["/opt/firefox-latest/YOUR_CA.pem"] }} }' >"/distribution/policies.json"

# Start from Selenium image and add relevant files from build image
FROM selenium/node-firefox:4.20.0-20240425
USER root
COPY --from=build /certs /opt/firefox-latest
COPY --from=build /distribution /opt/firefox-latest/distribution
USER seluser

Debugging

This project uses x11vnc as a VNC server to allow users to inspect what is happening inside the container. Users can connect to this server in two ways:

Using a VNC client

The VNC server is listening to port 5900, you can use a VNC client and connect to it. Feel free to map port 5900 to any free external port that you wish.

The internal 5900 port remains the same because that is the configured port for the VNC server running inside the container. You can override it with the SE_VNC_PORT environment variable in case you want to use --net=host.

Here is an example with the standalone images, the same concept applies to the node images.

$ docker run -d -p 4444:4444 -p 5900:5900 --shm-size="2g" selenium/standalone-chrome:4.20.0-20240425
$ docker run -d -p 4445:4444 -p 5901:5900 --shm-size="2g" selenium/standalone-edge:4.20.0-20240425
$ docker run -d -p 4446:4444 -p 5902:5900 --shm-size="2g" selenium/standalone-firefox:4.20.0-20240425

Then, you would use in your VNC client:

  • Port 5900 to connect to the Chrome container
  • Port 5901 to connect to the Edge container
  • Port 5902 to connect to the Firefox container

If you get a prompt asking for a password, it is: secret. If you wish to change this, you can set the environment variable SE_VNC_PASSWORD.

If you want to run VNC without password authentication you can set the environment variable SE_VNC_NO_PASSWORD=1.

If you want to run VNC in view-only mode you can set the environment variable SE_VNC_VIEW_ONLY=1.

If you want to modify the open file descriptor limit for the VNC server process you can set the environment variable SE_VNC_ULIMIT=4096.

Using your browser (no VNC client is needed)

This project uses noVNC to allow users to inspect visually container activity with their browser. This might come in handy if you cannot install a VNC client on your machine. Port 7900 is used to start noVNC, so you will need to connect to that port with your browser.

Similarly to the previous section, feel free to map port 7900 to any free external port that you wish. You can also override it with the SE_NO_VNC_PORT environment variable in case you want to use --net=host.

Here is an example with the standalone images, the same concept applies to the node images.

$ docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:4.20.0-20240425
$ docker run -d -p 4445:4444 -p 7901:7900 --shm-size="2g" selenium/standalone-edge:4.20.0-20240425
$ docker run -d -p 4446:4444 -p 7902:7900 --shm-size="2g" selenium/standalone-firefox:4.20.0-20240425

Then, you would use in your browser:

If you get a prompt asking for a password, it is: secret.

Disabling VNC

If You are running low on resources, or simply don't need to inspect running sessions, it is possible to not run VNC at all. Just set SE_START_VNC=false environment variable on the grid startup.


Tracing in Grid

In order to enable tracing in the Selenium Grid container, the following commands can be executed:

docker network create grid
docker run -d -p 16686:16686 -p 4317:4317 --net grid --name jaeger jaegertracing/all-in-one:1.54
docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4.20.0-20240425
docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
	-e SE_ENABLE_TRACING=true \
	-e SE_OTEL_TRACES_EXPORTER=otlp \
	-e SE_OTEL_EXPORTER_ENDPOINT=http://jaeger:4317 \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-chrome:4.20.0-20240425
docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
	-e SE_ENABLE_TRACING=true \
	-e SE_OTEL_TRACES_EXPORTER=otlp \
	-e SE_OTEL_EXPORTER_ENDPOINT=http://jaeger:4317 \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-edge:4.20.0-20240425
docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
    --shm-size="2g" \
	-e SE_ENABLE_TRACING=true \
	-e SE_OTEL_TRACES_EXPORTER=otlp \
	-e SE_OTEL_EXPORTER_ENDPOINT=http://jaeger:4317 \
    -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
    -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
    selenium/node-firefox:4.20.0-20240425

You can also refer to the below docker compose yaml files to be able to start a simple grid (or) a dynamic grid.

You can view the Jaeger UI and trace your request.


Troubleshooting

All output gets sent to stdout, so it can be inspected by running:

$ docker logs -f <container-id|container-name>

You can increase the log output by passing environment variable to the containers:

SE_OPTS="--log-level FINE"

--shm-size="2g"

Why is --shm-size 2g necessary?

This is a known workaround to avoid the browser crashing inside a docker container, here are the documented issues for Chrome and Firefox. The shm size of 2gb is arbitrary but known to work well, your specific use case might need a different value, it is recommended to tune this value according to your needs.

Headless

If you see the following selenium exceptions:

Message: invalid argument: can't kill an exited process

or

Message: unknown error: Chrome failed to start: exited abnormally

The reason might be that you've set the START_XVFB environment variable to "false", but forgot to actually run Firefox, Chrome or Edge in headless mode.

Mounting volumes to retrieve downloaded files

A common scenario is mounting a volume to the browser container in order to retrieve downloaded files. This works well in Windows and macOS but not without workarounds in Linux. For more details, check this well-documented issue.

For example, while using Linux, you might be starting a container in the following way:

docker run -d -p 4444:4444 --shm-size="2g" \
  -v /home/ubuntu/files:/home/seluser/Downloads \
  selenium/standalone-chrome:4.20.0-20240425

That will mount the host /home/ubuntu/files directory to the /home/seluser/Downloads inside the container (default browser's downloads directory). The problem happens because the volume will be mounted as root; therefore, the browser cannot write a file to that directory because it is running under the user seluser. This happens because that is how Docker mounts volumes in Linux, more details in this issue.

A workaround for this is to create a directory on the host and change its permissions before mounting the volume. Depending on your user permissions, you might need to use sudo for some of these commands:

mkdir /home/ubuntu/files
chown 1200:1201 /home/ubuntu/files

After doing this, you should be able to download files to the mounted directory. If you have a better workaround, please send us a pull request!

Mounting volumes to retrieve video files

Similar to mount volumes to retrieve downloaded files. For video files, you might need to do the same

mkdir /tmp/videos
chown 1200:1201 /tmp/videos

Stargazers over time

Stargazers over time

docker-selenium's People

Contributors

abaldwin-op avatar alexgibson avatar amardeep2006 avatar chenrui333 avatar ddavison avatar dependabot[bot] avatar diemol avatar doofus100500 avatar elgalu avatar garagepoort avatar jamesmortensen avatar jeff-jk avatar jsa34 avatar kayabendroth avatar luisfcorreia avatar maccracken avatar manoj9788 avatar marten-cz avatar metajiji avatar mtcolman avatar mtscout6 avatar niqo avatar pablofuente avatar renovate[bot] avatar selenium-ci avatar testphreak avatar tnguyen14 avatar vietnd96 avatar willabides avatar zainabsalameh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-selenium's Issues

run 2 or more containers on the save server with unique ports

By default node starts on port 5555 and you can only run on container per machine.

If you want to run more than one you have to specify -port 5556 for example.

We are managing our containers with docker::run and currently there is no way to start a more than one container per server becuase only one service can run on port 5555.

TODO: create PR where NODE can be given HOST and PORT to be accessible from the outside world.

Current solution of having REMOTE_HOST only addresses the part about the HOST but not PORT which by default is always 5555.

Example of puppet code:


docker::run { 'selenium-node-1':
      image           => "$image",
      env             => ["NODE_HOST=$fqdn", "NODE_PORT=5558", "HUB_PORT_4444_TCP_ADDR=$hub_addr", "HUB_PORT_4444_TCP_PORT=$hub_port"],
      ports           => ['5558:5558'],
      pull_on_start   => true
    }

docker::run { 'selenium-node-2':
      image           => "$image",
      env             => ["NODE_HOST=$fqdn", "NODE_PORT=5559", "HUB_PORT_4444_TCP_ADDR=$hub_addr", "HUB_PORT_4444_TCP_PORT=$hub_port"],
      ports           => ['5559:5559'],
      pull_on_start   => true
    }

the above puppet manifest snippet for selenium-node-2 is equivalent to running docker as:

docker run -d -p 5559:5559 -e NODE_ADDR="$(facter -p fqdn)" -e NODE_PORT="5559" -e HUB_PORT_4444_TCP_ADDR="foo" -e HUB_PORT_4444_TCP_PORT="4444" selenium/node-firefox

I could run it as following

docker run -d -p 5556:5555 -e REMOTE_HOST="http://$(facter -p fqdn):5556" -e HUB_PORT_4444_TCP_ADDR="foo" -e HUB_PORT_4444_TCP_PORT="4444" selenium/node-firefox

but once I run this I can't start a new container on 5555 since that port is already used.

We can offload all the configuratoion of node to the json file like we do with hub but I think I should be able to configure how the container is being executed and on port outside of the json config of the node itself.

Food for thought?

'-P' option doesn't forward hub container exposed port

when i run this command docker run -P -d --name selenium-hub selenium/hub i cant access hub console. I did this command instead docker run -d -p 4444:4444 --name selenium-hub selenium/hub and i can access the console at localhost:4444

FireFox Native Events

I can't seem to enable native events when using Firefox Standalone. I've tried by creating a FireFox profile on the remote end and within the container, but I can't seem to get it to work. How does one go about doing this?

Nodes require docker --link

The NodeBase/entry_point.sh checks for the environment variable $HUB_PORT_4444_TCP_ADDR, but executes selenium server hardcoded with http://hub:4444/

This makes it hard to run the images in any orchestrating frameworks, as most of them does not manipulate the hosts on the containers (or use dockers link feature).

Selenium Docker NodeChrome proxy isssue

I've setup selenium grid in a private network which requires use of proxy box to access development pages, therefore I'm having to add proxy configurations to selenium docker chrome nodes.

I had a look at docker-selenium/NodeChrome/config.json (below), there isn't a key to add IP/Hostname but port is there, bit strange this. Are test team supposed to have proxy configured in test suites? Even then there should be a way to configure proxy in browser nodes. Am I missing something?

"configuration": {
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"port": 5555,
"register": true,
"registerCycle": 5000
}

Cannot open browser in Docker container

Observed result:

Cannot connect to virtual display

07:39:51.778 INFO - Executing: [new session: Capabilities [{platform=ANY, browserName=firefox, version=}]])
07:39:51.780 INFO - Creating a new session for Capabilities [{platform=ANY, browserName=firefox, version=}]
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
(process:87): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Error: cannot open display: :99.0
(process:95): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Error: cannot open display: :99.0
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)

Expected result:

  • browser is started,

Steps to reproduce:

  • start docker-selenium hub
  • start docker-selenium node
docker run -i -t --cap-add=NET_ADMIN -p 5555:5555 selenium/node-firefox /bin/bash

java -jar ./opt/selenium/selenium-server-standalone.jar -role wd -hub http://<hostname>:4444/grid/register -browser browserName="firefox",maxInstances=1

Environment

  • CentOS
  • selenium 2.45.0
  • selenium/hub
  • selenium/node-chrome
  • selenium/node-firefox
  • docker-selenium firefox node as well as chrome

Workaround

docker run -i -t --cap-add=NET_ADMIN -p 5555:5555 selenium/node-firefox /bin/bash
Xvfb :1 -screen 0 1024x768x16 &
export DISPLAY=:1
java -jar ./opt/selenium/selenium-server-standalone.jar -role wd -hub http://<hostname>:4444/grid/register -browser browserName="firefox",maxInstances=1

Set up some kind of CI server

This project would be a lot cooler with a continuous integration server testing pull requests. I'm thinking something like drone.io or travis-ci would be nice.

I'll look into the viability of doing Docker tests with those two and report back here. If anybody has other suggestions, I'd love to hear them.

Include logo.png in the root of the repo

https://docs.docker.com/docker-hub/official_repos/#a-logo

A logo

Include a logo of your company or the product (png format preferred). Only one logo is required; you don’t need additional logo files for each tag. The logo file should have the following characteristics:

  • Be named logo.png
  • Should reside in the repo for the “latest” tag
  • Should fit inside a 200px square, maximized in one dimension (preferably the width)
  • Square or wide (landscape) is preferred over tall (portrait), but exceptions can be made based on the logo needed

Set log level to WARN?

In the readme it mentions all output is directed to stdout, however the log level appears to be INFO or lower.

I searched the repo and the only line referencing log level appears to be this one:

--enable-logging=stderr --log-level=0

Is modifying this shell script the only way to set a higher log level of, say, WARN? And is it possible to do that without forking this repo, changing that line, and then using my changed version? (My gut instinct is that there must be a more elegant way -- unless this feature has yet to be implemented)

Thanks in advance if anyone can answer this question; I appreciate all the great work you guys are doing here.

Standalone images

My use case doesn't require a grid.

I would like to run Selenium containers that are only used for one test.

Can we add standalone-firefox and standalone-chrome images for this use case?

Firefox node issue, browser hangs

Hello,

my firefox nodes (i am running docker on ubuntu server) seem to hang (100% reproduces), as using custom docker builds as using official via docker pull (chrome nodes work well).

I tried to execute firefox in the container, seems to be no display configured:

#docker run c6970094431e /usr/bin/firefox

(process:1): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Error: cannot open display: :99.0

If i execute docker logs $CID i see the following:

18:47:35.677 INFO - Executing: [new session: Capabilities [{platform=ANY, javascriptEnabled=true, browserName=firefox, version=}]])
18:47:35.678 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, browserName=firefox, version=}]
18:48:20.901 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'c9657e29a60a', ip: '172.17.0.34', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_65'
Driver info: driver.version: unknown
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:188)
        at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:175)
        at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:111)
        at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:88)
        at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:108)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:57)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:112)
        at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:172)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:201)
        at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:163)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:129)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
        at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
        at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
        at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
        at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
        at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
        at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
        at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
        at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
        at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
        at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
        at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'c9657e29a60a', ip: '172.17.0.34', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_65'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:69)
        at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:53)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:54)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:214)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:168)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:59)
        ... 9 more
Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:

(process:734): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Xlib:  extension "RANDR" missing on display ":99".
process 734: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/etc/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.

Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'c9657e29a60a', ip: '172.17.0.34', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_65'
Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:134)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
        ... 14 more
Caused by: org.openqa.selenium.WebDriverException: java.lang.InterruptedException: Process timed out after waiting for 45000 ms.
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'c9657e29a60a', ip: '172.17.0.34', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_65'
Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.os.CommandLine.waitFor(CommandLine.java:131)
        at org.openqa.selenium.firefox.FirefoxBinary.waitFor(FirefoxBinary.java:222)
        at org.openqa.selenium.firefox.FirefoxBinary.clean(FirefoxBinary.java:242)
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:91)
        ... 19 more
Caused by: java.lang.InterruptedException: Process timed out after waiting for 45000 ms.
        at org.openqa.selenium.os.UnixProcess.waitFor(UnixProcess.java:148)
        at org.openqa.selenium.os.CommandLine.waitFor(CommandLine.java:129)
        ... 22 more
18:48:20.904 WARN - Exception: Process timed out after waiting for 45000 ms.

Unable to set -remoteHost parameter for nodes without using custom config.json

Hi,

I've got this setup on separate hosts. So one host runs the HUB, and then several other hosts have nodes running on them. In this use case, I am unable to link containers, so I need to expose ports, and public IPs of hosts running nodes in order to connect to the HUB. Below is the example command that we use to start a node (replace 1.2.3.4 with IP of hub):

docker run -d -p 5555:5555 -e HUB_PORT_4444_TCP_ADDR="1.2.3.4" -e HUB_PORT_4444_TCP_PORT="4444" --name firefox-node selenium/node-firefox

What ends up happening, is the value for remoteHost gets set to the 'private' IP of the docker container itself. If you exec into a running docker container, and execute ipconfig, you'll see the IP that it uses. This is fine if you are 'linked' to the hub, but when running on separate hosts, the hub cannot contact the private IP. To enable this to work, we need support for -remoteHost parameter when starting the nodes.

-remoteHost is a built in parameter for selenium. More info available here: http://automatictester.co.uk/2012/10/27/selenium-grid-2-0-and-remotehost-parameter/

After this feature is implemented, we should be able to run nodes like this (notice the addition of the REMOTE_HOST env variable):

docker run -d -p 5555:5555 -e REMOTE_HOST="http://1.2.3.4:5555" -e HUB_PORT_4444_TCP_ADDR="1.2.3.4" -e HUB_PORT_4444_TCP_PORT="4444" --name firefox-node selenium/node-firefox

NOTE: In example above, you would need to provide correct IP for REMOTE_HOST and HUB, not the 1.2.3.4 that I provided as an example.

Can't set timezone in container

We're running into timezone issues because the docker-selenium containers have a different timezone than our host has. This is mostly due to this line in the Dockerfile:

ENV TZ "US/Pacific"

We can fix /etc/timezone and /etc/localtime by running the container with: -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:r, but that doesn't allow us to overwrite the TZ env var. This results in tools like date and Firefox still using the US/Pacific timezone.

Add PhantomJS support.

Should really add support for PhantomJS containers.

I have an active pull request for this issue: #38

This is an issue due to the need to potentially pull this image from the public docker registry as selenium/node-phantomjs:2.44.0

Currently have this image pushed through a different account (venturetech/node-phantomjs:2.44.0), but would like to keep all of the node images with the same naming convention within my scripts.

Investigate X11 forwarding as opposed to VNC

Initial issue derived from elgalu/docker-selenium#10

According to the Docker Official Repo Guidelines These images should not derive from phusion/baseimage. However, the initial reason to base off that image was to provide stability when running a Selenium node with VNC and Xvfb support.

There was an IRC conversation with @psftw regarding a possible means of utilizing a separate container for debug purposes using X11 forwarding. This approach would remove the need to support VNC in the same container as the Selenium node, thus getting us one step closer to a more efficient image.

I have done some initial work on this on my personal x11 branch which is still a ROUGH DRAFT. In there I was able to achieve using Xvfb and the Selenium node in a single process tree. The next goal is to figure out how to attach another container and perform an SSH connection with X11 forwarding.

docker-selenium/test.sh sanity script fails to run Firefox tests

The test.sh script is meant to run a sanity test against both node-chrome and node-firefox, but is exiting with a success status after running only the node-chrome test. It appears that the command string that gets passed to npm in the Test container (via the $TEST_CMD variable set in Test/Dockerfile and referenced in Test/package.json) is being evaluated as a binary with a list of arguments rather than a raw shell command.

The value set in Dockerfile is node smoke-chrome.js && node smoke-firefox.js but modifying the first script to print node's argument list shows:

[ 'node',
  '/usr/src/app/smoke-chrome.js',
  '&&',
  'node',
  'smoke-firefox.js' ]

This has something to do with using the environment variable in package.json rather than a literal command string. Replacing the variable reference with the actual command results in both test scripts running successfully.

" Failed to read: session.screen0.*" on firefox debug node startup

Hi,

I was trying to setup selenium grid with fig and docker on Mac OS. But on a startup every node was complaining about same problems :

node2_1 | 16:10:34.265 INFO - Starting auto register thread. Will try to register every 5000 ms.
node2_1 | 16:10:34.265 INFO - Registering the node to hub :http://172.17.0.7:4444/grid/register
node2_1 | Failed to read: session.screen0.opaqueMove
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.fullMaximization
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.maxIgnoreIncrement
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.maxDisableMove
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.maxDisableResize
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.workspacewarping
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.showwindowposition
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.autoRaise
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.clickRaises
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.defaultDeco
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tab.placement
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.windowMenu
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.noFocusWhileTypingDelay
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.workspaces
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.edgeSnapThreshold
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.window.focus.alpha
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.window.unfocus.alpha
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.menu.alpha
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.menuDelay
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tab.width
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tooltipDelay
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.allowRemoteActions
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.clientMenu.usePixmap
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabs.usePixmap
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabs.maxOver
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabs.intitlebar
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.focusModel
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabFocusModel
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.focusNewWindows
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.focusSameHead
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.rowPlacementDirection
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.colPlacementDirection
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.windowPlacement
node2_1 | Setting default value
node2_1 | Xlib:  extension "RANDR" missing on display ":99.0".
node2_1 | Failed to read: session.ignoreBorder
node2_1 | Setting default value
node2_1 | Failed to read: session.forcePseudoTransparency
node2_1 | Setting default value
node2_1 | Failed to read: session.colorsPerChannel
node2_1 | Setting default value
node2_1 | Failed to read: session.doubleClickInterval
node2_1 | Setting default value
node2_1 | Failed to read: session.tabPadding
node2_1 | Setting default value
node2_1 | Failed to read: session.styleOverlay
node2_1 | Setting default value
node2_1 | Failed to read: session.slitlistFile
node2_1 | Setting default value
node2_1 | Failed to read: session.appsFile
node2_1 | Setting default value
node2_1 | Failed to read: session.tabsAttachArea
node2_1 | Setting default value
node2_1 | Failed to read: session.cacheLife
node2_1 | Setting default value
node2_1 | Failed to read: session.cacheMax
node2_1 | Setting default value
node2_1 | Failed to read: session.autoRaiseDelay
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.opaqueMove
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.fullMaximization
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.maxIgnoreIncrement
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.maxDisableMove
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.maxDisableResize
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.workspacewarping
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.showwindowposition
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.autoRaise
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.clickRaises
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.defaultDeco
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tab.placement
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.windowMenu
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.noFocusWhileTypingDelay
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.workspaces
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.edgeSnapThreshold
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.window.focus.alpha
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.window.unfocus.alpha
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.menu.alpha
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.menuDelay
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tab.width
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tooltipDelay
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.allowRemoteActions
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.clientMenu.usePixmap
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabs.usePixmap
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabs.maxOver
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabs.intitlebar
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.focusModel
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.tabFocusModel
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.focusNewWindows
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.focusSameHead
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.rowPlacementDirection
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.colPlacementDirection
node2_1 | Setting default value
node2_1 | Failed to read: session.screen0.windowPlacement
node2_1 | Setting default value
node2_1 | 29/01/2015 16:10:34
node2_1 | 29/01/2015 16:10:34 Scroll Detection: -scrollcopyrect mode is in effect to
node2_1 | 29/01/2015 16:10:34   use RECORD extension to try to detect scrolling windows
node2_1 | 29/01/2015 16:10:34   (induced by either user keystroke or mouse input).
node2_1 | 29/01/2015 16:10:34   If this yields undesired behavior (poor response, painting
node2_1 | 29/01/2015 16:10:34   errors, etc) it may be disabled via: '-noscr'
node2_1 | 29/01/2015 16:10:34   Also see the -help entry for tuning parameters.
node2_1 | 29/01/2015 16:10:34   You can press 3 Alt_L's (Left "Alt" key) in a row to
node2_1 | 29/01/2015 16:10:34   repaint the screen, also see the -fixscreen option for
node2_1 | 29/01/2015 16:10:34   periodic repaints.
node2_1 | 29/01/2015 16:10:34
node2_1 | 29/01/2015 16:10:34 XKEYBOARD: number of keysyms per keycode 7 is greater
node2_1 | 29/01/2015 16:10:34   than 4 and 51 keysyms are mapped above 4.
node2_1 | 29/01/2015 16:10:34   Automatically switching to -xkb mode.
node2_1 | 29/01/2015 16:10:34   If this makes the key mapping worse you can
node2_1 | 29/01/2015 16:10:34   disable it with the "-noxkb" option.
node2_1 | 29/01/2015 16:10:34   Also, remember "-remap DEAD" for accenting characters.
node2_1 | 29/01/2015 16:10:34
node2_1 | 29/01/2015 16:10:34 X FBPM extension not supported.
node2_1 | 29/01/2015 16:10:34 X display is not capable of DPMS.
node2_1 | 29/01/2015 16:10:34 --------------------------------------------------------
node2_1 | 29/01/2015 16:10:34
node2_1 | 29/01/2015 16:10:34 Default visual ID: 0x21
node2_1 | 29/01/2015 16:10:34 Read initial data from X display into framebuffer.
node2_1 | 29/01/2015 16:10:34 initialize_screen: fb_depth/fb_bpp/fb_Bpl 24/32/5440
node2_1 | 29/01/2015 16:10:34
node2_1 | 29/01/2015 16:10:34 X display :99.0 is 32bpp depth=24 true color
node2_1 | 29/01/2015 16:10:34
node2_1 | 29/01/2015 16:10:34 Listening for VNC connections on TCP port 5900
node2_1 | 29/01/2015 16:10:34 Listening for VNC connections on TCP6 port 5900
node2_1 | 29/01/2015 16:10:34 listen6: bind: Address already in use
node2_1 | 29/01/2015 16:10:34 Not listening on IPv6 interface.
node2_1 | 29/01/2015 16:10:34 fb read rate: 1306 MB/sec
node2_1 | 29/01/2015 16:10:34 fast read: reset -wait  ms to: 10
node2_1 | 29/01/2015 16:10:34 fast read: reset -defer ms to: 10
node2_1 | 29/01/2015 16:10:34 The X server says there are 10 mouse buttons.
node2_1 | 29/01/2015 16:10:34 screen setup finished.
node2_1 | 29/01/2015 16:10:34
node2_1 |
node2_1 | The VNC desktop is:      a8225954779d:0

What this all complains mean and how could i connect to it through vnc? I tried all possible solutions, but it doesn't work for me.
In my bashrc file i have

export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH=/Users/biercoff/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1

and i tried to run

vncviewer 192.168.59.103:49155

but ended up with an error. I also tried to access to vnc of each node, but with no success :

docker inspect $(docker ps -q) | grep IPA
"IPAddress": "172.17.0.13",
        "IPAddress": "172.17.0.11",
        "IPAddress": "172.17.0.9",
        "IPAddress": "172.17.0.7",
vncviewer 172.17.0.11:49155

And as a result - an error. What am i'm doing wrong ?

Thanks in advance

How to use this?

How exactly do I get this running correctly on OSX? I have boot2docker installed and when I run docker pull or docker run, sometimes it starts up, sometimes I get a certificate error (which I have to wipe all and restart docker).

I also get this error sometimes:

An error occurred trying to connect: Post https://192.168.59.103:2376/v1.19/containers/create: dial tcp 192.168.59.103:2376: i/o timeout

So when I do get the docker image running, attempts to connect to it over VNC fail.

Nodes will occasionally hang, seemingly forever

Firefox-Node log (Missing the last 'Done:')

21:06:53.553 INFO - Executing: [get: http://172.17.42.1:8080/])
21:06:53.599 INFO - Done: [get: http://172.17.42.1:8080/]
21:06:53.613 INFO - Executing: [find element: By.selector: [node-name='account-body'] tr])

Selenium-Hub log

21:27:54.078 INFO - Got a request to create a new session: Capabilities [{platform=ANY, firefox_profile=UEsDBBQACAAIAHt7ikUAAAAAAAAAA..., javascriptEnabled=true, browserName=firefox, version=}]
21:27:54.078 INFO - Available nodes: [host :http://172.17.0.6:5555, host :http://172.17.0.4:5555, host :http://172.17.0.5:5555, host :http://172.17.0.3:5555]
21:27:54.078 INFO - Trying to create a new session on node host :http://172.17.0.6:5555
21:27:54.078 INFO - Trying to create a new session on test slot {platform=LINUX, seleniumProtocol=WebDriver, browserName=firefox, maxInstances=1}
[ec2-user@ci ~]$ sudo docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
selenium/node-firefox   2.44.0              8f4193404eb1        3 hours ago         558.2 MB
selenium/hub            2.44.0              4a9111e45347        3 hours ago         337.8 MB

Setting up VNC fails

When trying to use the 'standalone-chrome-debug' image I cannot connect to the vnc port.

In the logs I see:
09/07/2015 01:59:50 passing arg to libvncserver: -rfbport
09/07/2015 01:59:50 passing arg to libvncserver: 5900
Enter VNC password: stty: standard input: Inappropriate ioctl for device
fgets: No such file or directory
stty: standard input: Inappropriate ioctl for device
x11vnc -usepw: could not find a password to use.
Failed to read: session.ignoreBorder

It seems that vnc tries to 'obfuscate' the password that is entered in the tty, but that is not possible in stty.

Chrome setInterval() limits for inactive tab

This bug / feature in chrome means that tests take forever to run...

https://codereview.chromium.org/6577021

What happens is that chrome opens up with the Selenium window then another window (tab) is opened that starts a test. The test will progress slowly unless the original tab is selected due to inactive tab setInterval() calls being limited to at least 1000ms between calls.

-- Use WebWorker to avoid the issue --
http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome

-- Force it to open a new window, avoiding the limit --
http://stackoverflow.com/questions/15818892/chrome-javascript-window-open-in-new-tab

Sorry if this is not an issue with Selenuim directly but please correct me if it is an issue with the tests themselves.

selenium/hub, selenium/node-firefox, selenium/node-chrome won't start

I'm running a brand-new install of openSUSE 13.2. When I attempt to run selenium-hub containers, they exit with exit status 1. There is no log output.

I've tried both 2.44 and 2.45 versions, and I've even tried running bash:

me@me:~/mydir> docker run -d -p 4444:4444 --name selenium-hub selenium/hub:2.45.0
e6631b834889a412f64bedb0ab4ed40ce42059c7c26d3b347575c3a2353b344e
FATA[0000] Error response from daemon: Cannot start container e6631b834889a412f64bedb0ab4ed40ce42059c7c26d3b347575c3a2353b344e:  (exit status 1)
me@me:~/mydir> docker run -it -p 4444:4444 --name selenium-hub selenium/hub:2.45.0 bash
FATA[0000] Error response from daemon: Cannot start container 25bd245240f7952b3870c3c3e32d07eb1f71dd8a75fd5b2f8d74e3e1260a3cea:  (exit status 1)

Start vnc with docker exec instead of having separate debug images

Instead of having separate debug images, we could use the main images for debugging after running a docker exec command to start a vnc service. I've created willroden/se-chrome-standalone-plus as a proof-of-concept that extends standalone-chrome and adds start_vnc.sh and x11vnc to allow you to enable vnc through docker exec $CONTAINER /opt/bin/start_vnc.sh

This has two main benefits:

  1. Reduces the number of images to maintain
  2. Complies with the requirement to not have multiple processes running by default on any images (because the extra vnc process only runs with intervention)

The only drawback I can think of is adding to the size of the default images. IMO, this is a small increase, but should be considered nonetheless.

Replace base image with Ubuntu

Since the phusion/baseimage has not been sanctioned as an Official Docker Repo, we need to change to one that is.

This will break the VNC support used in debugging.

An option to mitigate this until #2 is resolved is to define an image with VNC support that derives from the sanctioned node images, to which we do not seek official sanctions by docker. Then when #2 is resolved we can remove those images.

Cannot connect to VNC server

Thanks for the great work with this repo.

I'm having trouble connecting to the VNC server to debug why my selenium tests are failing. I've tried with multiple vnc clients on both mac and linux but without joy. I've also tried connecting without SSL in case the certificate missing was the issue.

I've tried connecting to:
127.0.0.1:49155
localhost:49155
selenium-hub-ip:49155
selenium-chrome-debug-ip:49155

$ docker ps
CONTAINER ID        IMAGE                               COMMAND                CREATED              STATUS              PORTS                     NAMES
0e68a29b6bf8        selenium/node-chrome-debug:2.44.0   "/opt/bin/entry_poin   About a minute ago   Up About a minute   0.0.0.0:49155->5900/tcp   angry_brown         
6bab0f7039ab        selenium/hub:2.44.0                 "java -jar /opt/sele   58 minutes ago       Up About a minute   0.0.0.0:4444->4444/tcp    selenium-hub 

Any ideas where I'm going wrong?

Improve docker stop support

Currently when you run docker stop <container-id|container-name> the container does not shutdown gracefully.

Nodes with XVFB

Is there a case for providing an additional containers of browsers with XVFB?
We make extensive use of Selenium to test Flash applications and other non-headless scenarios.

Chrome and proxy environment variables

Chrome doesn't respect http_proxy andhttps_proxy environment variables.

I'm using the variables like this

https_proxy=http://user:[email protected]:8080
http_proxy=http://user:[email protected]:8080

I've also tried:

https_proxy=user:password@http://proxycorp.com:8080
http_proxy=user:password@http://proxycorp.com:8080

to no avail.

I've also used the uppercase variants like HTTP_PROXY and HTTPS_PROXY, with no success.

Chrome doesn't respect these environment variables.
In the debug images, I used bash to see if my environment variable exist, and they do. When I start the container in ENV I put the proxies environment variables.

When will a node container be ended and removed?

As stated in the readme, I like to remove the containers after each e2e test with --rm since this docker container is not meant to preserve state, I'm wondering when will each node container be stopped and removed? From what I see so far the node container simply continue running when the all test suites are completed.

Recovering from browser crashes takes a long time

I noticed that some of my tests looks for elements that was not ready, and this causes Firefox to crash.

As each Selenium node now just runs one instance of a browser, the node will not take any new sessions as it no longer have a working browser.

The documentation for Selenium Grid claims that the default "timeout" is 30 seconds, but I end up with having 300 seconds (and I can't find any source for this change).

This results that each node is out of operation for 300 seconds before it comes back into operation. When running a lot of tests suites where some of them do a lot in parallel I would need a lot of nodes.

I've played around with two workarounds for it:

  • Allowed each node more than 1 browser instance.
  • Set the "timeout" parameter to 30 seconds for the nodes.

Both approaches gives me a reasonably quickly self-healing Selenium Grid.

What is the reasoning between just one instance per node? And is there any hidden parameters that changes the default 30 seconds, or is just that documentation outdated?

official docker hub build process

I think we need to solve the problem of automated build on docker hub.

Our 11 images need to be built in ordered sequence (see Makefile):

  • base
  • hub, node-base
  • node-firefox, node-chrome
  • node-firefox-debug, node-chrome-debug
  • standalone-firefox, standalone-chrome
  • standalone-firefox-debug, standalone-chrome-debug

Problem: currently each Docker repo has an Automated Build active which creates race conditions when new commits trigger builds.

In order to create an ordered chain we can turn off deactivate Automated Build and:

  • build manually with the established sequence
  • or enable each build with trigger via curl in correct sequence

Thoughts? opinions?

AFAIK I dont't think docker hub provides build chains: https://docs.docker.com/v1.1/docker-hub/builds/

I like how CircleCI runs our build in sequence using make build defined in circle.yml but not docker hub.

I am now tempted to go with deactivating automated build and doing image release manually to avoid those race conditions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.