Test Overview
This test uses a custom wait condition to wait until a specific element's text changes to the expected value before proceeding. It verifies that the text update happens within the timeout.
This test uses a custom wait condition to wait until a specific element's text changes to the expected value before proceeding. It verifies that the text update happens within the timeout.
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 from selenium.common.exceptions import TimeoutException class text_to_be_updated: def __init__(self, locator, text): self.locator = locator self.text = text def __call__(self, driver): element = driver.find_element(*self.locator) if element.text == self.text: return element else: return False def test_custom_wait_condition(): driver = webdriver.Chrome() driver.get("https://example.com/dynamic_text") locator = (By.ID, "status") wait = WebDriverWait(driver, 10) try: element = wait.until(text_to_be_updated(locator, "Complete")) assert element.text == "Complete" except TimeoutException: assert False, "Text did not update to 'Complete' within 10 seconds" finally: driver.quit()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open with no page loaded | - | PASS |
| 2 | Browser navigates to https://example.com/dynamic_text | Page with element id='status' is loading dynamic text | - | PASS |
| 3 | WebDriverWait starts waiting up to 10 seconds for element with id='status' text to become 'Complete' | Element with id='status' initially shows different text (e.g., 'Loading...') | Check if element.text == 'Complete' | PASS |
| 4 | Custom wait condition __call__ method repeatedly checks element text | Element text changes from 'Loading...' to 'Complete' within timeout | Element text equals 'Complete' | PASS |
| 5 | Assertion verifies element.text is 'Complete' | Element text is 'Complete' as expected | assert element.text == 'Complete' | PASS |
| 6 | Browser closes and test ends | Browser window closed | - | PASS |