Docker + Compose + Selenium Grid = Automation awesomeness!
I have been trying to get my hands dirty with Docker and Selenium for a while. Finally what inspired me was a recent meetup where I saw some cool test automation reporting frameworks. No I did not see Docker there, but when I researched about Allure the test reporting framework I stumbled upon this cool video where the developer has used Docker Selenium and Allure:
Why Selenium Grid & Docker?
If you have been through the journey of CI (continuous integration), as an automation engineer you would know the challenges of building a reliable framework is time consuming.
This concept has revolutionized our way of thinking of how you build a selenium Grid, no more config mgmt/provisioning machines. All you need is a VM that can run the docker images as a container.
Contributors to this project who have made it a reality:
Matt Smith
Leo Galluci
The bigger challenge than that is the
- Virtual Machines / Networked physical machines / VDI etc
- They need to have the selenium server running correctly on them
- If something goes wrong debugging the node
- Collating data and reporting
Solutions:
The answer to the above problems is what we are looking at unless you want to spend some money to get SauceLabs/ BrowserStack / Rainforest. Here is a good diff between the three: (A topic for some other blog post)
Docker for the newbies:
If you haven't heard of Docker you haven't been reading blogs/attending meetups/conferences. In simple words Docker is a scaled down Virtual Machine that allows you to package all that you need - aaps - database - dependencies - configs - libraries - frameworks and so on into a standardized portable container.
For detailed info read on at the Docker's website - Build, Ship, Run
What happens when the two meet?
If you want speed , efficiency and something cool in the test automation world - Enter Docker Compose. Once you have read about Compose on the official site you would know where we are heading to: Pre-configured selenium clusters that run on newly spun Docker images
The three amigos of test automation:
- Selenium Grid - that manages routing of tests in a hub/nodes format
- Docker - that configures browser and apps
- Compose - The hub of the docker world that acts as central point from where everything is spun up on the go!
Fun facts:
- Docker images run as user-space processes on a shared OS
- These images are nothing but plain Dockerfiles
- http://odewahn.github.io/docker-jumpstart/building-images-with-dockerfiles.html
- Dockerfile
- Therefore these images share same resources
- but are still isolated and require far fewer resources to run than a VM
Let's get to the point:
1. Install Docker Compose - https://docs.docker.com/compose/install/
If you are using windows - https://docs.docker.com/engine/installation/windows/
2. Verify your installation
The installer places Docker Toolbox and VirtualBox in your Applications folder. In this step, you start Docker Toolbox and run a simple Docker command.
- On your Desktop, find the Docker Toolbox icon.
- Click the icon to launch a Docker Toolbox terminal.If the system displays a User Account Control prompt to allow Virtual-box to make changes to your computer. Choose Yes.The terminal does several things to set up Docker Toolbox for you. When it is done, the terminal displays the
$
prompt.The terminal runs a specialbash
environment instead of the standard Windows command prompt. Thebash
environment is required by Docker. - Type the
docker run hello-world
command or $ docker info
3. Selenium Grid Hub
Create the hub on localhost - download and run container from Docker repository with selenium hub:
$ docker pull selenium/hub
$ docker pull selenium/node-chrome
$ docker pull selenium/node-firefox
When the container is downloaded navigate to http://localhost:4444/grid/console and you should see an empty grid console$ docker pull selenium/hub
$ docker pull selenium/node-chrome
$ docker pull selenium/node-firefox
$ docker run -d ‐‐name seleniumAdy -hub -p 4444:4444 selenium/hub
4. Selenium Grid Nodes
Firefox profile
$ docker run -d -P ‐‐link selenium-hub:hub selenium/node-firefox
$ docker run -d --link selenium-hub:hub selenium/node-chrome:2.53.0
Chrome Profile:
$ docker run -d -P ‐‐link selenium-hub:hub selenium/node-chrome
$ docker run -d --link selenium-hub:hub selenium/node-chrome:2.53.0
https://hub.docker.com/r/selenium/
5. Validate the containers
$ docker logs hub
$ docker logs firefox
$ docker logs chrome
$ docker ps
Will list out all the containers(processes - ps) running. A hub and two nodes with Chrome and firefox$ docker logs firefox
$ docker logs chrome
$ docker ps
6. Bring it all together with docker-compose
- Stop all running containers $ docker stop $(docker ps -a -q)
- create docker-compose.yml file that will decide how the images interact - The nodes need to be linked to the hub and the ports need to be defined:
- Run it! $ docker-compose up -d
- Navigate to http://localhost:4444/grid/console and you should see everything as before , but with configs in a file
seleniumhub: image: selenium/hub ports: - 4444:4444 firefoxnode: image: selenium/node-firefox ports: - 8000 links: - seleniumhub:hub chromenode: image: selenium/node-chrome ports: - 8000 links: - seleniumhub:hub
7. Scale it up!
$ docker-compose scale chromenode=20
$ docker-compose scale firefoxnode=30
Adds more nodes to the hub!
8. Stop Docker
$ docker stop seleniumAdy
Happy Selenium Dockering!
Adds more nodes to the hub!
8. Stop Docker
$ docker stop seleniumAdy
Happy Selenium Dockering!
Excellent goods from you, man. I’ve understand your stuff previous to and you’re just too excellent. I actually like what you’ve acquired here, certainly like what you are stating and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I can not wait to read far more from you. This is actually a tremendous site..
ReplyDeleteLinux Training in Chennai
Nice post. This is the Docker image I use because it has VNC and video recording built in: https://github.com/elgalu/docker-selenium
ReplyDeleteThanks Francis!
DeleteOh yes I saw this one and that's the next thing to do.. I love how the video recordings have been embedded in reports.
Cheers,
Ady
is there a docker compose yml file just to spin up nodes and attached to a hub both running on differnet machine
ReplyDeleteThanks for the post! It led me down the path of using a standalone selenium Docker container for my project: https://bitbucket.org/dorianpula/rookeries/. This approach was a lot easier and faster to setup than the SauceLabs route I was going on previously.
ReplyDeleteGained so much latest info from your blog, thanks for the great content admin.
ReplyDeletePHP Training in Chennai
DOT NET Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Course in Chennai
JAVA Training in Chennai
Selenium training institute in Chennai
golden goose
ReplyDeletejordans shoes
air jordan
jordan shoes
kyrie 5
kd 12 shoes
kd shoes
yeezy boost 350 v2
calvin klein underwear
kd shoes
Source luxury replica bags Continue replica bags from china linked here replica bags online
ReplyDeleteThank you so much for your excellent blog! I really enjoy to visit your very interesting post, Well done!
ReplyDeleteChapter 7 Bankruptcy Lawyers Near Me
Cost of Uncontested Divorce in Virginia
w6u02q4l29 a7c71k7u38 c9l40o7v08 t1h92m5u99 w6l07d4r71 m8h32k3y24
ReplyDeletepalm angels
ReplyDeletegoyard tote bag
supreme clothing
hermes outlet
goyard