
Selenium Grid 4 - Architecture and Communication

๐ What is Selenium Grid?
Selenium Grid is a powerful tool that enables parallel execution of tests across multiple browsers, devices, and operating systems. It helps teams run tests faster by distributing them across different machines, improving efficiency and scalability in test automation.
With Selenium Grid 4, the traditional Hub-Node model is replaced with a fully distributed architecture, making test execution more reliable and flexible.
**๐ฆ๐ฒ๐น๐ฒ๐ป๐ถ๐๐บ ๐๐ฟ๐ถ๐ฑ ๐ฐ ๐๐ฟ๐ฐ๐ต๐ถ๐๐ฒ๐ฐ๐๐๐ฟ๐ฒ ๐ฎ๐ป๐ฑ ๐๐ผ๐บ๐บ๐๐ป๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป**
Real-World Analogy: Selenium Grid 4 as a Ride-Sharing App
Think of Selenium Grid 4 like a ride-sharing app (e.g., Uber). Hereโs how the components relate:
| **Selenium Grid 4 Component - Ride-Sharing Analogy |
| **Router**ย - The ride-booking app |
| **Distributor** - The system that assigns drivers |
| **Session Map** - Tracks ongoing rides |
| **Node (Browser Instance)** - The car (which executes the ride/test) |
๐๐ผ๐ ๐ถ๐ ๐ช๐ผ๐ฟ๐ธ๐ ๐ถ๐ป ๐ฎ ๐ฅ๐ถ๐ฑ๐ฒ-๐ฆ๐ต๐ฎ๐ฟ๐ถ๐ป๐ด ๐๐ฝ๐ฝ:
1. A **passenger** (test script) opens the app and requests a ride.
2. The **ride-booking system** (Router) receives the request and forwards it.
3. The **dispatcher** (Distributor) finds an available **driver** (Node).
4. The **ride-tracking system** (Session Map) records the trip.
5. The **driver** (Node) picks up the passenger and completes the ride (executes the test).
6. Once done, the ride-tracking system removes the session, and the driver is free for new requests.
๐ฆ๐๐ฒ๐ฝ-๐ฏ๐-๐ฆ๐๐ฒ๐ฝ ๐๐ฟ๐ฒ๐ฎ๐ธ๐ฑ๐ผ๐๐ป ๐ผ๐ณ ๐ฆ๐ฒ๐น๐ฒ๐ป๐ถ๐๐บ ๐๐ฟ๐ถ๐ฑ ๐ฐ ๐๐ผ๐บ๐บ๐๐ป๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป
#### **Step 1: The Test Script Sends a Request**
- The test script (client) wants to **run a test on Chrome**.
- The script sends a request to the **Router** (like booking a ride).
#### **Step 2: Router Receives the Request**
- The **Router** (`http://localhost:4444`) is the **entry point** for all test requests.
- It **does not decide** where the test should run.
- Instead, it **forwards the request** to the **Distributor**.
#### **Step 3: Distributor Assigns a Node**
- The **Distributor** looks for an **available Node (browser machine)**.
- It checks:
ย - "Do we have a Node that supports Chrome?"
ย - "Is that Node free?"
- If a matching Node is available, the **Distributor assigns it**.
#### **Step 4: Session Map Records the Test**
- The **Session Map** keeps track of:
ย - Which test is running.
ย - On which **Node (machine)**.
ย - The current status of the test.
#### **Step 5: Node Executes the Test**
- The **assigned Node (Chrome browser on a machine)** starts running the test.
- It follows all Selenium commands.
- The **Session Map** ensures that the **Router** sends commands to the correct Node.
#### **Step 6: Test Execution Completes**
- Once the test is done, the **Node** closes the browser.
- The **Session Map removes the session** from its record.
- The **Node is now free for the next test**.
๐๐ฒ๐ ๐๐ผ๐ป๐ฐ๐ฒ๐ฝ๐๐ ๐ฆ๐๐บ๐บ๐ฎ๐ฟ๐
โ **No Hub-Node Model** โ Selenium Grid 4 replaces Hub-Node with a fully distributed system.ย ย
โ **Router Handles Requests** โ Like a ride-booking app, the Router sends test requests to the Distributor.ย ย
โ **Distributor Assigns Tests** โ Finds an available Node (Chrome, Firefox, Edge).ย ย
โ **Session Map Tracks Tests** โ Ensures that WebDriver commands reach the correct browser.ย ย
โ **Nodes Execute Tests** โ Multiple Nodes can run different tests simultaneously.ย ย
๐ช๐ต๐ ๐ง๐ต๐ถ๐ ๐ ๐ฎ๐๐๐ฒ๐ฟ๐?
- **More Scalable** ๐ โ You can easily add new Nodes without modifying the Grid setup.
- **More Efficient** โก โ Uses **event-based communication** instead of polling.
- **Easier to Use** โ โ A **single Router URL (`http://localhost:4444/wd/hub`)** handles everything.