Selenium Environment With Docker

prerequisite

  • Run the following command for removal of any current container running

docker rm -f $(docker ps -a -q)

docker rmi -f $(docker images -a)

Setup the environment for zelenium having 2 browsers. Run the following commands

  • Run the following command to run the zelenium container

docker pull elgalu/selenium

docker pull dosel/zalenium

docker run --rm -ti --name zalenium -p 4444:4444 \

-v /var/run/docker.sock:/var/run/docker.sock \

-v /tmp/videos:/home/seluser/videos \

--privileged dosel/zalenium start

Setup the environment for selenium grid having multiple browsers

  • Create a docker-compose.yml file

mkdir docker-compose.yml

  • Paste the content

version: '2'

services:

  chrome:

    image: selenium/node-chrome:4.7.2-20221219

    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

    ports:

      - "6900:5900"

  edge:

    image: selenium/node-edge:4.7.2-20221219

    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

    ports:

      - "6901:5900"

  firefox:

    image: selenium/node-firefox:4.7.2-20221219

    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

    ports:

      - "6902:5900"

  selenium-hub:

    image: selenium/hub:4.7.2-20221219

    ports:

      - "4442:4442"

      - "4443:4443"

      - "4444:4444"

  • Run the command to build the container

docker-compose up --build

  • Check the containers are up and running by this command

docker ps

  • It will prompt for a password . Enter “secret” and check the Remember password .

  • It will connect with the node