DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Spinnaker Meets Minikube: Part 1
  • Use KubeKey To Set Up a Kubernetes and KubeSphere Cluster With NFS Storage
  • How To Dockerize Mean Stack App
  • Getting Started With Windows Containers

Trending

  • Apache Spark 4.0: Transforming Big Data Analytics to the Next Level
  • Caching 101: Theory, Algorithms, Tools, and Best Practices
  • How to Format Articles for DZone
  • After 9 Years, Microsoft Fulfills This Windows Feature Request
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Set Up Selenium Docker – Make Parallel Execution Easy

Set Up Selenium Docker – Make Parallel Execution Easy

Learn how you can set up Selenium Docker to solve many of the limitations of Selenium Grid and make distributed testing easier.

By 
Arunkumar Velusamy user avatar
Arunkumar Velusamy
·
May. 18, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
18.3K Views

Join the DZone community and get the full member experience.

Join For Free

Selenium Grid supports distributed test execution and allows running tests on different machines against different browsers in parallel. This reduces execution time from days to hours. However, Selenium Grid setup and maintenance requires effort and has its own limitations.

  • The user needs to install browsers manually as required;
  • The user needs to ensure the proper Selenium libraries are in place in hub and node machines;
  • The user needs to ensure proper browser drivers are in place in node machines;
  • In case of the same browser with different versions being used, the user needs to set up all versions manually and ensure selenium node setup command is proper;
  • Scaling of browsers available is not easy; Node has to be brought down to increase browser instances and session which is not possible when tests are already running;
  • Requires constant maintenance as the machines had to be kept up and running at all times;
  • Setup cannot be changed from one machine to another machine easily.

Selenium Docker helps in setting up test labs with a grid in a few very easy and simple steps by removing all complexities. Selenium Docker has vastly improved the efficiency of automation and provides an ideal environment for distributed testing by addressing the above pain points. It allows us to spin up the grid/nodes and tear them down all in simple commands. By the end of this article, we will have the solution for all the limitations mentioned above.

Please visit the Docker website for more information on Docker. This article requires Docker installation as a prerequisite. You can verify Docker installation by running any of below commands:

docker ps -a

docker version

docker info

Deploying Selenium Grid on a Standalone Docker Container:

Selenium provides standalone grid server Docker images with Chrome and Firefox browsers already installed on it.

docker run -d -P -p "4444:4444" --name standalone_grid_chrome selenium/standalone-chrome


With this command, the Selenium standalone Chrome image will be downloaded and the server will be started on your local machine on port 4444.

Similarly, the Firefox standalone server also can be started.

docker run -d -P -p "4444:4444" --name standalone_grid_firefox selenium/standalone-firefox


Verify whether the running container is running or not using the following command or visiting the http://[your machine IP]:4444/grid/console url.

docker ps -a


Please note that the execution happening on these images is headless using Xvfb.

If you want to see your execution or debug your script step by step, you can use the selenium/standalone-chrome-debug or Firefox images. These images have a VNC server installed so you can use VNC viewer or any other VNC client.

docker run -d -P -p "4444:4444" --name standalone_grid_firefox selenium/standalone-firefox-debug

docker run -d -P -p "4444:4444" --name standalone_grid_chrome selenium/standalone-chrome-debug


By default, when there is no image tag specified, the latest image with the latest browser version is used. A specific version of the browser can also be used to create a standalone grid.

You should use the Docker image available with that browser version. For example, if you want to use Firefox 51.0, you can use the tag 3.5 tag next to the image name.

docker run -d -P -p "5554:4444" --name firefox_3.0 --link hub:hub selenium/node-firefox:3.0


All images are maintained with the tag on the Selenium Docker Hub.

Deploying Selenium Grid on Multiple Containers Using Docker Compose

Docker Compose is the tool that lets you deploy Selenium Grid in multiple containers. Docker Compose uses YAML files to configure application services like a hub. Chrome and Firefox will be the services in this case.

Create a docker-compose.yml file on your machine.

version: "2"

services:

 hub:

 image: selenium/hub

 ports:

  - 4444:4444

 environment:

  GRID_MAX_SESSION: 10

firefox:

 image: selenium/node-firefox

 depends_on:

  - hub

 environment:

  HUB_HOST: hub

  NODE_MAX_INSTANCES: 5

  NODE_MAX_SESSION: 5

 chrome:

 image: selenium/node-chrome

 depends_on:

  - hub

 environment:

  HUB_HOST: hub

  NODE_MAX_INSTANCES: 5

  NODE_MAX_SESSION: 5


  •  image - Selenium docker image name

  •  environment - used to configure environment variables for the hub and nodes.

  •  depends_on - used to maintain start up order

  •  HUB_HOST - used to connect nodes to the hub with its service name.

  •  NODE_MAX_INSTANCES - the number of instances of the same version of a browser that can run in node.

  •  NODE_MAX_SESSION- the number of browsers (any browser and version) that can run in parallel at a time in a node.

Note: NODE_MAX_SESSION overrides max instances settings by restricting the number of browser instances that can run in parallel.

Save the docker-compose.yml file and start the grid using the command:

docker-compose up -d


This will pull and run the images as a hub and nodes. The nodes will register and start communicating with the hub. You can check whether everything is running using below command.

You can also verify it in browser—http://[your machine IP]:4444/grid/console.

docker ps -a


If you want to increase the number of browser containers, you can use the scale option. This will create a specified number of chrome containers and the number of containers includes already running containers. The same scale option can be used to reduce browser containers; just provide numbers less than the existing number of containers (for example, to remove 3 from 5 containers, use scale=2).

docker-compose scale chrome=2


To stop all containers created using compose file:

docker-compose stop


To start all containers created using compose file:

docker-compose start


To start/stop all containers created using compose file:

docker-compose start #containerID

docker-compose stop #containerID


You can get the container ID using docker ps -a  command.

To stop and remove containers:


docker-compose down


Deploying Selenium Grid on Multiple Containers with different browsers and versions:

docker run -d -P -p "4444:4444" --name hub selenium/hub


docker run -d -P -p "5551:4444" --name chrome_latest --link hub:hub selenium/node-chrome

docker run -d -P -p "5552:4444" --name chrome_3.4.0 --link hub:hub selenium/node-chrome:3.4.0

docker run -d -P -p "5553:4444" --name chrome_3.0 --link hub:hub selenium/node-chrome:3.0



docker run -d -P -p "5556:4444" --name firefox_latest --link hub:hub selenium/node-firefox

docker run -d -P -p "5555:4444" --name firefox_3.4.0 --link hub:hub selenium/node-firefox:3.4.0

docker run -d -P -p "5554:4444" --name firefox_3.0 --link hub:hub selenium/node-firefox:3.0


After running above commands, a grid will be set up with 3 different versions of Chrome and Firefox each.


Difference Between Images and Containers:

Image

The file system and configuration of application which is used to create containers.

Container

A running instance of Docker images.

You can see all tagged versions of Selenium images on Docker Hub. For example, standalone-Chrome tags can be found in here.

Please note the difference between different image names:

standalone-firefox  : Image to create standalone grid

standalone-firefox-debug: Image to create standalone grid with debugging capability

node-firefox : Image to create selenium node that can be registered to hub


I hope that you found this useful in solving the limitations mentioned. You can also find this post on my blog.

Docker (software) Execution (computing) Machine Command (computing) File system

Published at DZone with permission of Arunkumar Velusamy. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Spinnaker Meets Minikube: Part 1
  • Use KubeKey To Set Up a Kubernetes and KubeSphere Cluster With NFS Storage
  • How To Dockerize Mean Stack App
  • Getting Started With Windows Containers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!