category-iconCASE STUDY

Selenium Grid 4 - Architecture and Communication

Anisur17 Mar 202504380
Blog Thumbnail

๐Ÿš€ 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.

seleniumwebautomationseleniumgridcrossbrowsertesting