Docker Selenium Grid helps run automated browser tests on many browsers and machines easily. It saves time by running tests in parallel without setting up each browser manually.
Docker Selenium Grid in Selenium Java
docker run -d -p 4444:4444 --name selenium-grid selenium/standalone-chrome // Java code to connect to Selenium Grid WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), new ChromeOptions());
Use docker run to start Selenium Grid containers.
In Java, use RemoteWebDriver with the Grid URL to run tests remotely.
docker run -d -p 4444:4444 --name selenium-grid selenium/standalone-firefox
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), new FirefoxOptions());docker network create selenium-grid-network docker run -d --net selenium-grid-network --name selenium-hub -p 4444:4444 selenium/hub docker run -d --net selenium-grid-network --name chrome-node -e HUB_HOST=selenium-hub selenium/node-chrome
This Java program connects to a Selenium Grid running on localhost. It opens the example.com website, checks the page title, and prints it. If the title is wrong, it throws an error.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.net.URL; public class SeleniumGridTest { public static void main(String[] args) throws Exception { ChromeOptions options = new ChromeOptions(); WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options); driver.get("https://example.com"); String title = driver.getTitle(); System.out.println("Page title is: " + title); if (!title.equals("Example Domain")) { throw new AssertionError("Title does not match expected value."); } driver.quit(); } }
Make sure Docker is installed and running before starting Selenium Grid containers.
Use the correct Grid URL and port in your test code (default is http://localhost:4444/wd/hub).
Always quit the WebDriver to free resources after the test finishes.
Docker Selenium Grid lets you run browser tests on many browsers and machines easily.
Use Docker commands to start Grid hub and nodes, then connect with RemoteWebDriver in Java.
This setup helps run tests faster and share environments with your team.