Site icon

Selenium Grid Setup with Docker Containers


In this tutorial, we will learn steps involved for running Selenium Grid Setup with Docker Containers. Docker is an app containerization platform. Let’s get started to setup the grid.

Pull Docker Images

Navigate to URL and search for Selenium Hub. We need to pull docker images from the Docker Repository Hub to get started with the Selenium grid setup.

Selenium Hub

Pull the Selenium Hub docker image.

\> docker pull selenium/hub


Selenium Nodes

Pull some Selenium Node docker images. In this example, we will use two nodes.

Pull the selenium nodes from the remote repository.

\> docker pull selenium/node-firefox

\> docker pull selenium/node-chrome


We can check the images using the docker local repository command.

\> docker images


Start Docker Containers

Start Selenium Hub

\> docker run -d -p 4444:4444 -P –name selenium-hub selenium/hub

Start Nodes

Start nodes and connect them with the Selenium Hub.

docker run -d –link selenium-hub:hub -P –name chrome selenium/node-chrome

docker run -d –link selenium-hub:hub -P –name firefox selenium/node-firefox


Verify Grid Console

Open Browser and navigate to the Grid console URL.



Sample Test

Run a sample test against the Grid Hub URL. The test just opens an URL and prints the title of the Web page. If we run multiple tests the hub would distribute the tests on the nodes.

package com.testingdocs.docker.demo;

import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;

public class SeleniumGridOnDockerTest {

	public void FBTestTestOnDocker() throws Exception {
		FirefoxOptions fOptions = new FirefoxOptions();
		URL remote = new URL("http://localhost:4444/wd/hub");
		WebDriver driver = new RemoteWebDriver(remote, fOptions);
		System.out.println(driver.getTitle() + 
" \ -Selenium Tutorials");
		System.out.println("Selenium Grid using Docker container."
				+ "Check the Docker Logs for more information!");


Sample Output

Execute the test and verify the Docker container logs.


Selenium WebDriver Tutorials on this website can be found at:

For more details on the Selenium, visit the official website at:

Exit mobile version