Setting Up Selenium Grid for Multi‐Node Execution in Cloud Environments - Nytrotype/Selenium-with-Java-automation-work GitHub Wiki
Introduction
Selenium Grid allows parallel test execution across multiple browsers, devices, and operating systems. Using Cloud-based execution, such as AWS, Azure, Sauce Labs, or LambdaTest, significantly enhances test scalability.
1. Why Use Selenium Grid in Cloud?
✅ Parallel Test Execution – Runs multiple tests simultaneously across nodes.
✅ Cross-Browser Testing – Supports Chrome, Edge, Firefox, and Safari.
✅ Cloud Scalability – Uses cloud infrastructure without local resource dependency.
✅ Reduced Execution Time – Speeds up automation workflows in CI/CD environments.
✅ Supports Docker & Kubernetes – Ideal for containerized test execution.
2. Setting Up Selenium Grid Locally
Step 1: Download Selenium Grid
- Get the latest Selenium Server from: https://www.selenium.dev/downloads/
- Place the JAR file in your workspace.
Step 2: Start Selenium Hub
Run this command to start the Hub (Controller):
java -jar selenium-server.jar hub
Verify hub is running at http://localhost:4444/grid/console.
Step 3: Start Node Instances
Run nodes to register with the hub:
java -jar selenium-server.jar node --hub http://localhost:4444
Specify browser capabilities in a JSON config file:
{
"capabilities": [
{
"browserName": "chrome",
"maxInstances": 3
},
{
"browserName": "firefox",
"maxInstances": 2
}
],
"hub": "http://localhost:4444"
}
Run:
java -jar selenium-server.jar node -config nodeConfig.json
3. Deploy Selenium Grid in Cloud (AWS, Azure, LambdaTest)
Option 1: AWS EC2 Deployment
✅ Step 1: Launch an EC2 instance with Java & WebDriver installed.
✅ Step 2: Upload Selenium Grid JAR & start the hub.
✅ Step 3: Register multiple remote nodes using EC2 instances.
Option 2: Azure DevOps Pipeline with Selenium Grid
✅ Step 1: Set up an Azure Virtual Machine running Selenium.
✅ Step 2: Start the hub and configure Cloud VM instances as nodes.
✅ Step 3: Integrate test execution into Azure DevOps pipelines.
Option 3: Using LambdaTest or Sauce Labs Selenium Grid
✅ Step 1: Create an account at LambdaTest/Sauce Labs.
✅ Step 2: Retrieve API credentials for cloud execution.
✅ Step 3: Configure Remote WebDriver in Java:
String cloudUrl = "https://USERNAME:[email protected]/wd/hub";
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "edge");
caps.setCapability("platform", "Windows 10");
WebDriver driver = new RemoteWebDriver(new URL(cloudUrl), caps);
4. Running Tests on Selenium Grid
✅ Parallel Test Execution – Configure TestNG for grid testing:
<suite name="Selenium Grid Suite" parallel="tests" thread-count="5">
✅ Docker-Based Selenium Grid – Deploy nodes using Docker Compose:
version: "3"
services:
selenium-hub:
image: selenium/hub
chrome:
image: selenium/node-chrome
depends_on:
- selenium-hub
5. Best Practices for Cloud-Based Selenium Grid
✅ Use Load Balancing – Distribute test execution across cloud instances.
✅ Enable Video Recording – Use Sauce Labs/LambdaTest for execution logs.
✅ Optimize Node Configurations – Adjust instance counts for efficiency.
✅ Monitor Grid Performance – Track execution metrics for test optimization.
Conclusion
Integrating Selenium Grid in cloud environments enhances test scalability, speed, and reliability across multiple browsers. Whether deploying on AWS, Azure, or cloud testing platforms, a structured setup ensures efficient parallel execution.