DEV Community

Arvind Choudhary
Arvind Choudhary

Posted on

Selenium Grid Setup with Docker

Hello readers,

from past few days I've been thinking about reducing automation test execution time by creating an environment where I could perform cross-browser and/or parallel execution.

I came-across once solution where we could leverage docker to setup selenium grid on our local machine.


Perquisite(software)

Docker

Commands to pull required images

pulling hub image
docker pull selenium/hub:latest

pulling node-chrome
docker pull selenium/node-chrome:latest

pulling node-firefox
docker pull selenium/node-firefox:latest

pulling node-edge
docker pull selenium/node-edge:latest

Commands to setup grid

creating custom network
docker network create grid

running hub image
docker run -d --rm -p 4442–4444:4442–4444 --net grid --name selenium-hub selenium/hub:latest

running node-chrome image
docker run -d --rm --net grid -e SE_EVENT_BUS_HOST=selenium-hub --name node-chrome -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 selenium/node-chrome:latest

running node-edge image
docker run -d --rm --net grid -e SE_EVENT_BUS_HOST=selenium-hub --name node-edge -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 selenium/node-edge:latest

running node-firefox image
docker run -d --rm --net grid -e SE_EVENT_BUS_HOST=selenium-hub --name node-firefox -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 selenium/node-firefox:latest

Check container status

docker ps
Image description

all your containers should have Status as Up

Grid UI:

navigate to http://localhost:4444/ui/index.html on your machine to open grid UI

Image description


Increasing instances for parallel execution on same browser

creating custom network
docker network create grid

running hub image
docker run -d --rm -p 4442–4444:4442–4444 --net grid --name selenium-hub selenium/hub:latest

running node-chrome image
docker run -d --rm --net grid -e SE_EVENT_BUS_HOST=selenium-hub --name node-chrome --shm-size="2g" -e SE_NODE_MAX_SESSIONS=8 -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 selenium/node-chrome:latest

running node-edge image
docker run -d --rm --net grid -e SE_EVENT_BUS_HOST=selenium-hub --name node-edge --shm-size="2g" -e SE_NODE_MAX_SESSIONS=8 -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 selenium/node-edge:latest

running node-firefox image
docker run -d --rm --net grid -e SE_EVENT_BUS_HOST=selenium-hub --name node-firefox --shm-size="2g" -e SE_NODE_MAX_SESSIONS=8 -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 selenium/node-firefox:latest

Grid UI:

Image description


Stopping containers & removing network

Once you are done with you testing you can remove container with the help of below command, where you run docker stop command by passing container names to stop them.

stopping container
docker stop node-chrome node-edge node-firefox selenium-hub

removing docker network
docker network rm grid

Discussion (0)