Docker configuration for selenium tests
Why docker for selenium testers:
Usually while configuring the Selenium grid we need to host
multiple virtual machines as nodes and we need to connect every single node
with the hub. Also, when we set up a normal grid we need to download the
Selenium server jar file and run that jar file on each computer in which we are
going to set up the Selenium grid.
This is costly and sometimes a time-consuming task for the
testers. However, Docker helps us to solve cost-related and time-consuming
problems.
Steps to create a automation project with the help of Docker:
-Create a Maven project
-Add selenium dependencies
-Create a class like below.This will print Google by executing test in container created from docker.
-Define and initialize a chromeStandAlone container in 4444 port.Below details gives details of docker.
Most used common Docker commands:
docker ps: Will give information of all containers
running in the machine.
Docker Images: will show all current images
docker pull <image name>: image will be
downloaded into machine.
Ex: docker pull selenium/standalone-chrome:87.0 (by
specifying the version)
docker
pull selenium/standalone-chrome:latest(will pull the latest version)
we can directly get commands in docker hub. See below.
Docker run: Will
deploy the image into container.
Now
Below is the
commands we have to run and these are readily available in documentation.
Ex: Chrome
$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm
selenium/standalone-chrome:4.0.0-beta-1-prerelease-20201208
·
d stands for run in background
·
4444/4444: means localport/containerport
·
-p: identifies 4444/4444 as port and redirects localport to
containerport.
Note:
We can set
up docker in two ways
1.
With executing commands manually one after
other. In below link it is explained this way.
Docker
Selenium Tutorial: How to Integrate Selenium Grid with Docker
(softwaretestinghelp.com)
2. Writing all configurations in docker file(.yml) then run that yml file through command prompt.This yaml is readily available in selenium git hub docker documentation.Always use the latest version.
Here is the link for sample compose file:
ddocker-selenium/docker-compose-v3.yml at trunk · SeleniumHQ/docker-selenium · GitHub
Using Compose is basically a three-step
process:
1. Define
your app’s environment with a Dockerfile so
it can be reproduced anywhere.
2. Define
the services that make up your app in docker-compose.yml so
they can be run together in an isolated environment.
Run docker-compose up and
Compose starts and runs your entire app
To increase
the browsers count in chrome node:





I was looking for info on docker and came across this. It provides just the info I needed. Thanks :)
ReplyDelete