Verify Selenium Grid setup by running a test on remote node
Preconditions (3)
✅ Expected Result: Test runs successfully on remote node via Selenium Grid and verifies the page title matches 'Example Domain'
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC def test_grid_remote_chrome(): # Setup Chrome options chrome_options = Options() chrome_options.add_argument('--headless') # Run headless for faster execution # URL of Selenium Grid Hub grid_url = 'http://localhost:4444/wd/hub' # Create Remote WebDriver session driver = webdriver.Remote( command_executor=grid_url, options=chrome_options ) try: # Navigate to example.com driver.get('https://example.com') # Wait until title is present WebDriverWait(driver, 10).until(EC.title_is('Example Domain')) # Assert page title assert driver.title == 'Example Domain', f"Expected title 'Example Domain' but got '{driver.title}'" finally: # Close browser session driver.quit() if __name__ == '__main__': test_grid_remote_chrome()
This script connects to a Selenium Grid Hub running locally on port 4444.
It uses webdriver.Remote with Chrome options to request a Chrome browser session on a remote node.
The test navigates to https://example.com and waits explicitly until the page title matches 'Example Domain'.
An assertion checks the page title to verify the page loaded correctly.
Finally, the browser session is closed with driver.quit() to free resources.
This setup confirms the Grid is correctly routing commands to a remote node.
Now add data-driven testing to run the same test on Chrome and Firefox browsers via the Grid
from selenium import webdriver
caps = {'browserName': 'firefox'}
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=caps)
driver.get('https://example.com')
print(driver.title)
What will be printed if the Grid and node are correctly set up?driver = webdriver.Remote('http://localhost:4444/wd/hub', {'browserName': 'chrome'})
What is the likely cause and how to fix it?Pass the test and this pattern moves unknown