Test Overview
This test demonstrates how Selenium Grid allows running multiple tests at the same time on different browsers or machines. It verifies that tests can start and finish independently without waiting for each other.
This test demonstrates how Selenium Grid allows running multiple tests at the same time on different browsers or machines. It verifies that tests can start and finish independently without waiting for each other.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.remote.webdriver import WebDriver import threading import time def run_test(node_url: str, browser_name: str): options = webdriver.ChromeOptions() if browser_name == 'chrome' else webdriver.FirefoxOptions() driver: WebDriver = webdriver.Remote( command_executor=node_url, options=options ) driver.get('https://example.com') heading = driver.find_element(By.TAG_NAME, 'h1').text assert heading == 'Example Domain', f'Heading mismatch on {browser_name}' time.sleep(2) # Simulate test steps driver.quit() if __name__ == '__main__': node1 = 'http://localhost:4444/wd/hub' node2 = 'http://localhost:4445/wd/hub' thread1 = threading.Thread(target=run_test, args=(node1, 'chrome')) thread2 = threading.Thread(target=run_test, args=(node2, 'firefox')) thread1.start() thread2.start() thread1.join() thread2.join()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and two threads are created for parallel execution | No browsers open yet, threads ready to run tests on different nodes | - | PASS |
| 2 | Thread 1 opens Chrome browser via Selenium Grid node at http://localhost:4444/wd/hub | Chrome browser window opens on node1, navigates to https://example.com | - | PASS |
| 3 | Thread 2 opens Firefox browser via Selenium Grid node at http://localhost:4445/wd/hub | Firefox browser window opens on node2, navigates to https://example.com | - | PASS |
| 4 | Thread 1 finds the heading element and asserts its text is 'Example Domain' | Chrome browser shows page with heading 'Example Domain' | Heading text equals 'Example Domain' | PASS |
| 5 | Thread 2 finds the heading element and asserts its text is 'Example Domain' | Firefox browser shows page with heading 'Example Domain' | Heading text equals 'Example Domain' | PASS |
| 6 | Both threads wait 2 seconds simulating test steps independently | Both browsers remain open and active on their respective nodes | - | PASS |
| 7 | Both threads close their browsers and end | No browsers open, threads complete execution | - | PASS |