0
0
Selenium Pythontesting~10 mins

Grid architecture (hub and node) in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test connects to a Selenium Grid hub and runs a simple browser test on a node. It verifies that the page title is correct, confirming the grid setup works.

Test Code - Selenium
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# Connect to Selenium Grid Hub
hub_url = "http://localhost:4444/wd/hub"

# Use Chrome browser on the node
capabilities = DesiredCapabilities.CHROME.copy()

# Create remote WebDriver session
driver = webdriver.Remote(command_executor=hub_url, desired_capabilities=capabilities)

try:
    # Open example page
    driver.get("https://example.com")

    # Assert page title
    assert driver.title == "Example Domain", f"Expected title 'Example Domain' but got '{driver.title}'"

finally:
    driver.quit()
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Create Remote WebDriver session connecting to Selenium Grid hub at http://localhost:4444/wd/hub with Chrome capabilitiesSelenium Grid hub is running and has at least one Chrome node registered-PASS
2Browser on node opens and navigates to https://example.comBrowser window is open on the node, loading the example.com page-PASS
3Check that the page title is exactly 'Example Domain'Page is fully loaded with title 'Example Domain'Assert driver.title == 'Example Domain'PASS
4Close the browser and end the sessionBrowser window is closed, session terminated-PASS
Failure Scenario
Failing Condition: Selenium Grid hub is not running or no nodes are available, or page title does not match expected
Execution Trace Quiz - 3 Questions
Test your understanding
What does the Remote WebDriver connect to in Selenium Grid architecture?
ADirectly to the browser on the node
BThe local machine's browser
CThe Selenium Grid hub URL
DThe test script file
Key Result
Always verify that the Selenium Grid hub and nodes are running and properly registered before running tests. This ensures your remote sessions can start and tests execute on the intended browsers.