TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Selenium Grid

Selenium Grid Setup with Docker Containers

Overview

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 https://hub.docker.com 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

Docker Selenium Hub

 

Selenium Nodes

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

  • selenium/node-firefox
  • selenium/node-chrome

Pull the selenium nodes from the remote repository.

\> docker pull selenium/node-firefox

\> docker pull selenium/node-chrome

 

Docker pull selenium Node Firefox

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

\> docker images

 

Docker Local Repository

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

Selenium Grid with Docker Containers Illustration

 

Verify Grid Console

Open Browser and navigate to the Grid console URL.

http://localhost:4444/grid/console

 

Docker Selenium Grid Console

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 java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;

public class SeleniumGridOnDockerTest {

 @Test
 public void FBTestTestOnDocker() throws Exception {
 FirefoxOptions fOptions = new FirefoxOptions();
 URL remote = new URL("http://localhost:4444/wd/hub");
 WebDriver driver = new RemoteWebDriver(remote, fOptions);
 driver.get("https://www.facebook.com");
 System.out.println(driver.getTitle() + 
" \nwww.TestingDocs.com -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 Grid on Docker Sample Test

 

—

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

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

https://www.selenium.dev/

Related Posts

Selenium Server Error

Selenium Grid /

Selenium Server Error: No drivers have been configured

Selenium4_Grid_Architecture

Selenium Grid /

Selenium 4 Grid Architecture

Selenium4_Grid_Components

Selenium Grid /

Selenium Grid 4.x Distributed Mode

Selenium 4 Standalone Grid

Selenium Grid /

Different Selenium Grid Modes in Selenium 4.0

Selenium grid foreground

Selenium Grid /

Run Selenium Grid in Background on Linux

‹ Get Started with Selenium Grid› Scalable Selenium Grid with Docker Compose

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com