In today’s newsletter we are going to discuss
Introduction
Docker Installation
Selenium Grid with Docker Compose
Starting Selenium Grid using Docker Compose
Running Parallel Tests on different browsers
GitHub Repo
Introduction
Selenium Grid is a tool in the Selenium suite that allows you to run Selenium tests concurrently across multiple machines and different browsers in parallel.
It's ideal for speeding up the execution of tests, especially when you want to test your application across various browser versions, platforms, or devices simultaneously.
Components of Selenium Grid
🔸Hub:
The Hub is the central server that manages the test distribution. It receives test requests and delegates them to appropriate nodes.
🔸Node:
Nodes are machines (physical or virtual) that execute the tests. They register themselves to the Hub, indicating the browsers they can run.
Docker Installation
As a prerequisite, Docker should be installed on your machine. You can download and install Docker from the official website (https://www.docker.com/get-started).
Once Docker Desktop installed on your machine then here are the steps to follow:
1. Open Docker Desktop.
Type the following command in your terminal:
docker run -d -p 80:80 docker/getting-started
Selenium Grid with Docker Compose
A Docker compose file is a YAML file that defines a set of Docker services. It can be used to define the services that make up an application, as well as the relationships between those services.
Official Selenium Grid docker compose yml file can be downloaded from here:
https://github.com/SeleniumHQ/docker-selenium/blob/trunk/docker-compose-v3.yml
Let’s break down this YAML file:
version: "3": This line specifies the version of the Docker Compose file syntax. The version "3" is used in this example.
services: This section defines the services (containers) that make up the Selenium Grid infrastructure.
image: Specifies the Docker image to use for chrome, Firefox, edge or selenium-hub
ports
:
Maps the host machine's port 4444, 4443 & 4442 to the container's port 4444, 4443, 4442. This allows external connections to the Selenium Grid hub.chrome, Firefox & edge : This section defines the Selenium Grid node service for Chrome, edge and Firefox.
depends_on
:
Indicates that the Chrome, Firefox and edge nodes depends on the hub service. Docker Compose ensures that the hub service starts before these nodes.environment
:
Theseselenium-hub: This section defines the Selenium Grid hub service.
Starting Selenium Grid using Docker Compose
Here are the steps to selenium Grid once above yaml file has been stored in your machine.
1. Open command Prompt and go to that file location where above yaml file is stored.
2. Execute below command to start Selenium Grid
Here ‘
docker-compose-v3.yml
’ is yaml file name.
docker-compose -f docker-compose-v3.yml up
Once above command is executed, it will start pulling image from repository as shown below.
Once above step is done, Selenium Grid is up and running on port 4444. We can check the status here.
http://localhost:4444/ui
Note: To Stop the grid, here is the command we can use.
docker-compose -f docker-compose-v3.yml down
Running Parallel Tests on different browsers
Once Selenium Grid is up and running on “http://localhost:4444/ui”,
next step is to execute tests.
We will execute tests in 3 different browsers parallel using selenium grid. Here is the code structure looks like.
As you can see, I have specified 3 different class “ChromeSeleniumGrid”, “FirefoxSeleniumGrid” and “EdgeSeleniumGrid” and we will execute these in parallel.
In TestNg XML file shown below we are executing tests in parallel and specifying thread count as 3 so we can execute all 3 browsers(chrome,firefox and edge) together.
Once we execute above TestNG xml file, here is what we see on “http://localhost:4444/ui”
As shown below, tests got executed on all 3 nodes.
If you browse to “Sessions” menu tab, it list down all the session details as below.
If you click on ‘video’, you will see below screen where you need to enter password ‘secret’.
Once you click on ‘Accept’, you will see below screens.
In Chrome
In Firefox
In Edge
GitHub Repository
You can find code of this newsletter issue at this GitHub Repository
The elevator to success is out of order. You’ll have to use the stairs… one step at a time.” – Joe Girard.
Let’s Connect on Social Media
Connect with me on LinkedIn (7.7K+ Followers) and Twitter.