Test Overview
This test uses Selenium with a Docker-based Selenium Grid to open a browser, navigate to a website, find a button by its ID, click it, and verify the page title changes as expected.
This test uses Selenium with a Docker-based Selenium Grid to open a browser, navigate to a website, find a button by its ID, click it, and verify the page title changes as expected.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Connect to Selenium Grid running in Docker options = webdriver.ChromeOptions() driver = webdriver.Remote( command_executor='http://localhost:4444/wd/hub', options=options ) try: driver.get('https://example.com') # Wait until button with id 'start-btn' is present wait = WebDriverWait(driver, 10) button = wait.until(EC.presence_of_element_located((By.ID, 'start-btn'))) button.click() # Wait until title changes to expected value wait.until(EC.title_is('Started Page')) assert driver.title == 'Started Page', f"Expected title 'Started Page' but got '{driver.title}'" finally: driver.quit()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Selenium Remote WebDriver connects to Docker Selenium Grid at http://localhost:4444/wd/hub | Selenium Grid is running in Docker, ready to provide browser session | - | PASS |
| 2 | Browser session opens and navigates to 'https://example.com' | Browser window shows the example.com homepage | - | PASS |
| 3 | Waits up to 10 seconds for button with id 'start-btn' to appear | Button with id 'start-btn' is present on the page | Element with id 'start-btn' is found | PASS |
| 4 | Clicks the button with id 'start-btn' | Page reacts to button click, navigation or content changes | - | PASS |
| 5 | Waits until page title changes to 'Started Page' | Page title is now 'Started Page' | Page title equals 'Started Page' | PASS |
| 6 | Asserts that the page title is exactly 'Started Page' | Page title matches expected value | assert driver.title == 'Started Page' | PASS |
| 7 | Test ends and browser session quits | Browser closes, Selenium Grid session ends | - | PASS |