Test Overview
This test opens a web page, waits until a button becomes clickable using Selenium's expected conditions, clicks the button, and verifies that a success message appears.
This test opens a web page, waits until a button becomes clickable using Selenium's expected conditions, clicks the button, and verifies that a success message appears.
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 TestExpectedConditions(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/testpage') def test_button_clickable_and_message(self): driver = self.driver wait = WebDriverWait(driver, 10) # Wait until the button with id 'submit-btn' is clickable button = wait.until(EC.element_to_be_clickable((By.ID, 'submit-btn'))) button.click() # Wait until the success message with id 'success-msg' is visible success_msg = wait.until(EC.visibility_of_element_located((By.ID, 'success-msg'))) self.assertEqual(success_msg.text, 'Success!') 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 and navigated to 'https://example.com/testpage' | - | PASS |
| 2 | Wait until the button with id 'submit-btn' is clickable using WebDriverWait and expected_conditions.element_to_be_clickable | Button with id 'submit-btn' is present and enabled on the page | Check that the button is clickable | PASS |
| 3 | Click the button with id 'submit-btn' | Button is clicked, triggering page action | - | PASS |
| 4 | Wait until the success message with id 'success-msg' is visible using expected_conditions.visibility_of_element_located | Success message element appears on the page | Check that the success message text equals 'Success!' | PASS |
| 5 | Test ends and browser closes | Browser window is closed | - | PASS |