Test Overview
This test opens a webpage, waits explicitly for a button to appear using WebDriverWait, clicks it, and verifies the resulting message is displayed.
This test opens a webpage, waits explicitly for a button to appear using WebDriverWait, clicks it, and verifies the resulting message is displayed.
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 import unittest class TestExplicitWait(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/wait_test') def test_click_button_after_wait(self): driver = self.driver wait = WebDriverWait(driver, 10) button = wait.until(EC.element_to_be_clickable((By.ID, 'delayed-button'))) button.click() message = wait.until(EC.visibility_of_element_located((By.ID, 'result-message'))) self.assertEqual(message.text, 'Button clicked!') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to load the test page | - | PASS |
| 2 | Navigates to 'https://example.com/wait_test' | Page is loading or loaded with initial content | - | PASS |
| 3 | Waits up to 10 seconds for button with ID 'delayed-button' to be clickable using WebDriverWait | Button appears and becomes clickable after a delay | Button is clickable | PASS |
| 4 | Clicks the 'delayed-button' | Button is clicked, triggering page update | - | PASS |
| 5 | Waits up to 10 seconds for element with ID 'result-message' to be visible | Result message appears on page | Result message text equals 'Button clicked!' | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |