Grid architecture helps run tests on many browsers and machines at the same time. It saves time and checks if your website works everywhere.
Grid architecture (hub and node) in Selenium Python
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # Connect to the Selenium Grid Hub driver = webdriver.Remote( command_executor='http://hub_ip:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME ) # Use the driver to open a website driver.get('https://example.com') # Close the browser driver.quit()
The command_executor URL points to the hub where tests are sent.
DesiredCapabilities tells which browser you want to use on the node.
driver = webdriver.Remote(
command_executor='http://192.168.1.10:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX
)driver = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.EDGE
)This script connects to a Selenium Grid hub running locally, opens Chrome on a node, visits example.com, prints the page title, and closes the browser.
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # Connect to Selenium Grid Hub hub_url = 'http://localhost:4444/wd/hub' try: driver = webdriver.Remote( command_executor=hub_url, desired_capabilities=DesiredCapabilities.CHROME ) driver.get('https://example.com') title = driver.title print(f'Page title is: {title}') finally: driver.quit()
Make sure the Selenium Grid Hub is running before starting tests.
Nodes must be registered to the hub and have the requested browsers installed.
Use IP addresses or hostnames reachable from your test machine for the hub URL.
Grid architecture uses a hub to control many nodes (machines with browsers).
Tests connect to the hub, which sends them to the right node.
This helps run tests faster and on many browsers at once.
Practice
hub in Selenium Grid architecture?Solution
Step 1: Understand the hub's function in Selenium Grid
The hub acts as a central point that receives test requests from clients.Step 2: Identify how the hub manages nodes
The hub distributes these requests to the right nodes that have the required browser and platform.Final Answer:
To receive test requests and distribute them to the appropriate nodes -> Option CQuick Check:
Hub controls nodes [OK]
- Thinking the hub runs browsers directly
- Confusing hub with node responsibilities
- Assuming hub stores test data
Solution
Step 1: Recall the command syntax for starting a hub
The correct command uses '-role hub' to specify the hub role.Step 2: Compare options with correct syntax
java -jar selenium-server.jar -role hub matches the correct syntax: 'java -jar selenium-server.jar -role hub'.Final Answer:
java -jar selenium-server.jar -role hub -> Option AQuick Check:
Hub starts with '-role hub' flag [OK]
- Using '-role node' instead of '-role hub'
- Incorrect flag order or spelling
- Using '-start' or '-node start' which are invalid
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities hub_url = "http://localhost:4444/wd/hub" driver = webdriver.Remote(command_executor=hub_url, desired_capabilities=DesiredCapabilities.CHROME) print(driver.capabilities['browserName']) driver.quit()
Solution
Step 1: Analyze the desired capabilities used
The code requests a Chrome browser by using DesiredCapabilities.CHROME.Step 2: Understand the output of driver.capabilities['browserName']
This returns the name of the browser the remote driver is connected to, which should be 'chrome'.Final Answer:
chrome -> Option DQuick Check:
DesiredCapabilities.CHROME = 'chrome' output [OK]
- Assuming default browser is Firefox
- Confusing capability keys
- Not quitting driver causing errors
java -jar selenium-server.jar -role node -hub http://localhost:4444/grid/registerBut the node is not registering with the hub. What is the most likely cause?
Solution
Step 1: Check the hub URL and hub status
If the node cannot register, often the hub URL is wrong or the hub is not running.Step 2: Verify command correctness
The command uses '-role node' correctly; the jar file corruption or start order is less common causes.Final Answer:
The hub URL is incorrect or the hub is not running -> Option AQuick Check:
Node needs correct hub URL and running hub [OK]
- Mixing up node and hub roles in commands
- Assuming jar file corruption without evidence
- Starting node before hub is usually okay
Solution
Step 1: Understand Selenium Grid architecture
The hub acts as a central controller, and nodes register to it with different browsers.Step 2: Identify correct multi-browser setup
Multiple nodes on different machines with different browsers register to one hub to run tests in parallel.Final Answer:
One hub running on a central machine, multiple nodes registered with different browsers on different machines -> Option BQuick Check:
Single hub, multiple nodes with browsers [OK]
- Thinking multiple hubs are needed for parallel tests
- Confusing roles of hub and node
- Running nodes without a hub
Ready to prove it?
Pass the test and this pattern moves unknown
