
Cross-browser testing with Selenium Grid ensures that web applications work consistently across different browsers and environments. By combining Selenium Grid with Docker, you can create a scalable test infrastructure that runs automated tests remotely and in parallel.
This guide demonstrates how to set up Selenium Grid using Docker and execute cross-browser tests on Chrome and Firefox using Java, Selenium WebDriver, Maven, and TestNG. The CrossBrowserTest class dynamically connects to a remote Selenium Grid and runs the same test across multiple browsers.
Prerequisites
Before configuring Selenium Grid with Docker, make sure the following tools are installed:
- Java Development Kit (JDK) 8 or later
- Apache Maven for dependency management
- Selenium WebDriver libraries
- TestNG framework
- Docker Desktop
- Google Chrome and Mozilla Firefox
- ChromeDriver and GeckoDriver (optional for local execution)
Setting Up Cross-Browser Testing with Selenium Grid Using Docker
Docker simplifies Selenium Grid deployment by creating isolated containers for the hub and browser nodes. This setup enables efficient cross-browser testing and supports parallel execution.
Step 1: Install Docker
Install Docker Desktop and ensure the Docker service is running.
Step 2: Create a Docker Network for Selenium Grid
Create a dedicated network for communication between the Selenium Hub and browser nodes.
docker network create grid
Step 3: Start the Selenium Hub
Run the Selenium Hub container and expose port 4444.
docker run -d -p 4444:4444 --net grid --name selenium-hub selenium/hub
Step 4: Add Chrome and Firefox Nodes to Selenium Grid
Launch browser containers and connect them to the Selenium Hub.
docker run -d --net grid --name chrome -e HUB_HOST=selenium-hub selenium/node-chromedocker run -d --net grid --name firefox -e HUB_HOST=selenium-hub selenium/node-firefox
Step 5: Verify Selenium Grid
Open the Selenium Grid console:
http://localhost:4444
You should see both Chrome and Firefox nodes registered and ready for test execution.
Running Cross-Browser Tests with Selenium Grid
Once Selenium Grid is running, execute your Selenium tests using Maven.
Run all tests:
mvn clean test
Run tests specifically on Chrome:
mvn test -Dbrowser=chrome
Run tests on Firefox:
mvn test -Dbrowser=firefox
The CrossBrowserTest class connects to the remote Selenium Grid and executes the same test scenario across different browsers. This approach helps identify browser-specific issues and ensures a consistent user experience.

Benefits of Cross-Browser Testing with Selenium Grid and Docker
Using Selenium Grid and Docker for cross-browser testing offers several advantages:
- Execute tests on Chrome and Firefox from a centralized grid.
- Run tests in parallel to reduce execution time.
- Scale browser nodes easily by adding more containers.
- Isolate browser environments using Docker containers.
- Improve test reliability and maintainability.
- Support continuous integration and automated pipelines.
Conclusion
This provides an efficient and scalable solution for browser automation. By running tests remotely on Chrome and Firefox, teams can validate application behavior across multiple environments while reducing execution time through parallel testing.
This Docker-based Selenium Grid setup integrates seamlessly with Java, Selenium WebDriver, Maven, and TestNG, making it ideal for automated testing in modern CI/CD pipelines.
For additional configuration options, refer to the official Selenium Grid documentation and Docker Selenium images maintained by SeleniumHQ. Find the below useful links:
Selenium Grid Documentation: https://www.selenium.dev/documentation/grid
Selenium Docker Images: https://github.com/SeleniumHQ/docker-selenium
Docker Documentation: https://docs.docker.com
TestNG Documentation: https://testng.org/doc
Related Articles
Discover more from Rotebit
Subscribe to get the latest posts sent to your email.


Pingback: Selenium Grid Explained - Rotebit